使用msn协议运行twisted.words示例的问题

时间:2009-04-25 13:16:30

标签: python twisted msn twisted.words

我目前正在尝试使用特定扭曲词的Twisted库来尝试与MSN进行交互。但是当我运行twisted提供的示例脚本时,我收到错误。具体而言,错误发现在http://i42.tinypic.com/wl945w.jpg。该脚本可以在http://twistedmatrix.com/projects/words/documentation/examples/msn_example.py找到。

平台是使用Python 2.6的Vista

编辑:完整输出:

Email (passport): mypassport@hotmail.com
Password: ******
2009-04-25 10:52:49-0300 [-] Log opened.
2009-04-25 10:52:49-0300 [-] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x9d87e8c>
2009-04-25 10:52:55-0300 [Dispatch,client] Starting factory <twisted.words.protocols.msn.NotificationFactory instance at 0x9e28bcc>
2009-04-25 10:52:55-0300 [Dispatch,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x9d87e8c>
2009-04-25 10:52:55-0300 [Notification,client] Unhandled Error
    Traceback (most recent call last):
      File "/usr/local/lib/python2.5/site-packages/twisted/python/log.py", line 84, in callWithLogger
        return callWithContext({"system": lp}, func, *args, **kw)
      File "/usr/local/lib/python2.5/site-packages/twisted/python/log.py", line 69, in callWithContext
        return context.call({ILogContext: newCtx}, func, *args, **kw)
      File "/usr/local/lib/python2.5/site-packages/twisted/python/context.py", line 59, in callWithContext
        return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "/usr/local/lib/python2.5/site-packages/twisted/python/context.py", line 37, in callWithContext
        return func(*args,**kw)
    --- <exception caught here> ---
      File "/usr/local/lib/python2.5/site-packages/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
        why = getattr(selectable, method)()
      File "/usr/local/lib/python2.5/site-packages/twisted/internet/tcp.py", line 460, in doRead
        return self.protocol.dataReceived(data)
      File "/usr/local/lib/python2.5/site-packages/twisted/protocols/basic.py", line 238, in dataReceived
        why = self.lineReceived(line)
      File "/usr/local/lib/python2.5/site-packages/twisted/words/protocols/msn.py", line 651, in lineReceived
        handler(params.split())
      File "/usr/local/lib/python2.5/site-packages/twisted/words/protocols/msn.py", line 827, in handle_USR
        d = _login(f.userHandle, f.password, f.passportServer, authData=params[3])
      File "/usr/local/lib/python2.5/site-packages/twisted/words/protocols/msn.py", line 182, in _login
        reactor.connectSSL(_parsePrimitiveHost(nexusServer)[0], 443, fac, ClientContextFactory())
    exceptions.TypeError: 'NoneType' object is not callable

2009-04-25 10:52:55-0300 [Notification,client] Stopping factory <twisted.words.protocols.msn.NotificationFactory instance at 0x9e28bcc>

2 个答案:

答案 0 :(得分:3)

由于MSN涉及SSL连接,因此必须安装pyOpenSSL才能使用它。好像你可能没有。但是,这并不是Twisted报告此缺失依赖项的好方法。我建议在Twisted问题跟踪器中提交票证以改进此报告。

答案 1 :(得分:2)

发生了什么

当您尝试调用None对象时,会遇到此异常。看看这个:

>>> a = str
>>> a() # it's ok, a string is a callable class
''
>>> a = None
>>> a() # it fails, None a special Singleton not meant to be called

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    a()
TypeError: 'NoneType' object is not callable

你能做什么

你无法猜到这一点,所以你需要进行一些调试。

显然,最后一行(refactor.connectSSL ...)包含三个对象调用,其中一个对象是None。

你可以做的第一件事,如果你没有进入调试器,如果要采用该行的每个元素并添加,就在它之前:

assert object1 is None 
assert object2 is None

然后你将获得你的例外的来源。之后,检查为什么此对象设置为None。您可能必须检查文档以查看在哪种情况下可能已启动它的某些方法返回None。

愿部队......