帮助我理解twisted.words msn示例中的这个回溯

时间:2009-08-07 13:36:16

标签: python twisted msn traceback

我正在运行来自扭曲文档的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:

有人可以帮我理解这意味着什么吗?

2 个答案:

答案 0 :(得分: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]

我们可以看到服务器正在向客户端发送一条消息,指明该帐户的未读电子邮件数量。

希望有所帮助!

答案 1 :(得分:0)

方法gotMessage声称没有实现。这可能意味着你已经在子类中重写了需要getMessage的类的子类,但是你没有完成重写。