首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MSN协议运行twisted.words示例的异常

使用MSN协议运行twisted.words示例的异常
EN

Stack Overflow用户
提问于 2012-05-12 18:54:53
回答 1查看 268关注 0票数 1

我正在从位于这里的Twisted文档运行twisted.words MSN协议示例:example.py

然而,当我运行这个示例脚本时,我得到了这个UnhandledError异常:

代码语言:javascript
复制
2012-05-12 15:39:51-0300 [-] Log opened.
2012-05-12 15:39:51-0300 [-] Starting factory <twisted.internet.protocol.ClientFactory instance at  0x8c6c18c>
2012-05-12 15:39:52-0300 [Dispatch,client] Starting factory <twisted.words.protocols.msn.NotificationFactory instance at 0x8c6c2cc>
2012-05-12 15:39:52-0300 [Dispatch,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x8c6c18c>
2012-05-12 15:39:53-0300 [Notification,client] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x8c710ec>
2012-05-12 15:39:53-0300 [Notification,client] Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
    why = getattr(selectable, method)()
  File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 460, in doRead
    rval = self.protocol.dataReceived(data)
  File "/usr/lib/python2.7/dist-packages/twisted/protocols/basic.py", line 564, in dataReceived
    why = self.lineReceived(line)
  File "/usr/lib/python2.7/dist-packages/twisted/words/protocols/msn.py", line 670, in lineReceived
    handler(params.split())
  File "/usr/lib/python2.7/dist-packages/twisted/words/protocols/msn.py", line 848, in handle_USR
    authData=params[3])
  File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 108, in execute
    return succeed(result)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 71, in succeed
    d.callback(result)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 360, in callback
    assert not isinstance(result, Deferred)
exceptions.AssertionError: 

2012-05-12 15:39:53-0300 [Notification,client] Stopping factory <twisted.words.protocols.msn.NotificationFactory instance at 0x8c6c2cc>
2012-05-12 15:39:55-0300 [PassportNexus,client] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x8d014cc>
2012-05-12 15:39:55-0300 [PassportNexus,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x8c710ec>
2012-05-12 15:39:56-0300 [PassportLogin,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x8d014cc>
  • Python 2.7.2+
  • 扭曲11.0.0
  • pyOpenSSL 0.12
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-14 16:26:45

我以前从未使用过t.w.protocols.msn协议,但在我看来,在Twisted的msn.py on 第846项中有一个bug。下面是所讨论的功能:

代码语言:javascript
复制
def handle_USR(self, params):
    if len(params) != 4 and len(params) != 6:
        raise MSNProtocolError, "Invalid Number of Parameters for USR"

    mechanism = params[1]
    if mechanism == "OK":
        self.loggedIn(params[2], unquote(params[3]), int(params[4]))
    elif params[2].upper() == "S":
        # we need to obtain auth from a passport server
        f = self.factory
        d = execute(                                                   # <------- here
            _login, f.userHandle, f.password, f.passportServer,
            authData=params[3])
        d.addCallback(self._passportLogin)
        d.addErrback(self._passportError)

defer.executemsn._login及其参数一起被调用,但是msn._login应该返回一个延迟推断。将defer.execute与可能返回延迟的函数一起使用是不合适的,因为它将立即包装到另一个通过defer.succeed推断的Deferreds中,并且Deferreds无法将其他Deferreds作为结果保存。

那里的execute调用应该使用defer.maybeDeferred。如果您将maybeDeferred添加到文件顶部的twisted.internet.defer导入中,并将此execute调用更改为maybeDeferred调用,那么它将开始工作(或者至少由于不同的bug :)而开始失败。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10566516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档