I’m running the twisted.words MSN protocol example from the Twisted documentation located here: http://twistedmatrix.com/projects/words/documentation/examples/msn_example.py
However when I run this sample script, I get that UnhandledError exception:
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+
- Twisted 11.0.0
- pyOpenSSL 0.12
I’ve never used the t.w.protocols.msn protocol before, but it looks to me like there’s a bug in Twisted’s
msn.pyon line 846. Here’s the function in question:defer.executeis called withmsn._loginand its parameters, butmsn._loginis supposed to return a Deferred. It’s not appropriate to usedefer.executewith a function that might return a Deferred, since it will be immediately wrapped in another Deferred viadefer.succeed, and Deferreds can not hold other Deferreds as results.The
executecall there should be usingdefer.maybeDeferredinstead. I would expect that if you addmaybeDeferredto the imports fromtwisted.internet.deferat the top of the file and change thisexecutecall to amaybeDeferredcall, it will start working (or at least start failing due to a different bug 🙂 ).