gpt4 book ai didi

python - 使用 MSN 协议(protocol)运行 twins.words 示例时出现异常

转载 作者:行者123 更新时间:2023-12-01 06:00:50 25 4
gpt4 key购买 nike

我正在运行位于此处的 Twisted 文档中的 twinsed.words MSN 协议(protocol)示例:http://twistedmatrix.com/projects/words/documentation/examples/msn_example.py

但是,当我运行此示例脚本时,我收到 UnhandledError 异常:

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

最佳答案

我以前从未使用过 t.w.protocols.msn 协议(protocol),但在我看来,line 846 上的 Twisted 的 msn.py 中存在错误。 。这是有问题的函数:

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.execute 使用 msn._login 及其参数调用,但 msn._login 应该返回 Deferred。将 defer.execute 与可能返回 Deferred 的函数一起使用是不合适的,因为它会立即通过 defer.succeed 包装在另一个 Deferred 中,并且 Deferred 不能保存其他延期结果。

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

关于python - 使用 MSN 协议(protocol)运行 twins.words 示例时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com