【问题标题】:Help me understand this traceback from the twisted.words msn sample帮助我从 twisted.words msn 示例中了解此回溯
【发布时间】:2010-11-17 16:49:06
【问题描述】:

我正在运行来自这里的 twisted 文档的 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:

有人可以帮我理解这是什么意思吗?

【问题讨论】:

    标签: python twisted msn traceback


    【解决方案1】:

    gotMessage 方法声称未实现。这可能意味着您已将需要在子类中覆盖 gotMessage 的类进行子类化,但您尚未完成覆盖。

    【讨论】:

    • 这段代码是从twisted words 文档中完美复制粘贴。这可能与 msn 协议的更改有关吗?还是我更可能缺少依赖库或类似的东西?
    • 好像是twisted这部分的API发生了变化,但我不熟悉所以不知道。
    【解决方案2】:

    看起来这是对 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]
    

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

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 2021-07-01
      • 2011-11-03
      • 2011-11-17
      相关资源
      最近更新 更多