3

ここにあるツイスト ドキュメントから twisted.words msn プロトコルの例を実行しています: http://twistedmatrix.com/projects/words/documentation/examples/msn_example.py

stackoverflow のこのサンプル .py について別の質問があることは承知していますが、これはまったく別の問題です。この例を実行すると、期待どおりに動作します。アカウントにログインし、バディリストのユーザーに関する情報を表示しますが、その後、このトレースバックを吐き出します

> Traceback (most recent call last):  
> File
> "c:\python26\lib\site-packages\twisted\python\log.py",
> line 84, in callWithLogger
>     return callWithContext({"system": lp}, func, *args, **kw)   File
> "c:\python26\lib\site-packages\twisted\python\log.py",
> line 69, in callWithContext
>     return context.call({ILogContext: newCtx}, func, *args, **kw)   File
> "c:\python26\lib\site-packages\twisted\python\context.py",
> line 59, in callWithContext
>     return self.currentContext().callWithContext(ctx,
> func, *args, **kw)   File
> "c:\python26\lib\site-packages\twisted\python\context.py",
> line 37, in callWithContext
>     return func(*args,**kw)
> --- <exception caught here> ---   File "c:\python26\lib\site-packages\twisted\internet\selectreactor.py",
> line 146, in _doReadOrWrite
>     why = getattr(selectable, method)()   File
> "c:\python26\lib\site-packages\twisted\internet\tcp.py",
> line 463, in doRead
>     return self.protocol.dataReceived(data)  
> File
> "c:\python26\lib\site-packages\twisted\protocols\basic.py", line 239, indataReceived
>     return self.rawDataReceived(data)   File
> "c:\python26\lib\site-packages\twisted\words\protocols\msn.py",
> line 676 in rawDataReceived
>     self.gotMessage(m)   File "c:\python26\lib\site-packages\twisted\words\protocols\msn.py",
> line 699, in gotMessage
>     raise NotImplementedError exceptions.NotImplementedError:

誰かがそれが何を意味するのか理解するのを手伝ってもらえますか?

4

2 に答える 2

1

MSN サーバーの動作方法が変更されたように見えますが、実際にはプロトコルの変更とはみなされません。クライアントが接続した直後に MSN サーバーがクライアントにメッセージを送信しており、Twisted words の例ではそれが予期されていません。

http://twistedmatrix.com/projects/words/documentation/examples/から msn_example.py を実行していると仮定すると、次のコードを例に追加することで、例が機能し、何が起こっているかを確認できます (最後の直後にlistSynchronized 関数の):

def gotMessage(self, message):
    print message.headers
    print message.getMessage()

変更を行った後、例を実行すると、次のように表示されます。

...
2009-08-25 00:03:23-0700 [Notification,client] {'Content-Type': 'text/x-msmsgsinitialemailnotification; charset=UTF-8', 'MIME-Version': '1.0'}
2009-08-25 00:03:23-0700 [Notification,client] Inbox-Unread: 1
2009-08-25 00:03:23-0700 [Notification,client] Folders-Unread: 0
2009-08-25 00:03:23-0700 [Notification,client] Inbox-URL: /cgi-bin/HoTMaiL
2009-08-25 00:03:23-0700 [Notification,client] Folders-URL: /cgi-bin/folders
2009-08-25 00:03:23-0700 [Notification,client] Post-URL: http://www.hotmail.com
2009-08-25 00:03:23-0700 [Notification,client]

サーバーが、そのアカウントの未読メール メッセージの数を指定するメッセージをクライアントに送信していることがわかります。

それが役立つことを願っています!

于 2009-08-25T07:10:32.170 に答える
0

メソッド gotMessage は実装されていないと主張しています。これは、サブクラスで gotMessage をオーバーライドする必要があるクラスをサブクラス化したが、オーバーライドを行っていないことを意味する可能性があります。

于 2009-08-07T13:48:11.827 に答える