<div class="gmail_quote">On Wed, Mar 3, 2010 at 1:56 PM, Werner Thie <span dir="ltr"><<a href="mailto:wthie@thiengineering.ch">wthie@thiengineering.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi<br>
<br>
Starting twistd xmpp-router and trying to connect to it with a component<br>
from the wokkel examples<br>
<br>
"""<br>
An XMPP Ping server as an external server-side component.<br>
<br>
This ping server assumes the domain C{'ping'}.<br>
"""<br>
import sys<br>
<br>
from twisted.python import log<br>
from twisted.application import app, service, internet<br>
from twisted.internet import reactor<br>
<br>
from wokkel import component<br>
from wokkel.ping import PingHandler<br>
<br>
# Configuration parameters<br>
EXT_HOST = 'localhost'<br>
EXT_PORT = 5347<br>
SECRET = 'secret'<br>
DOMAIN = 'ping'<br>
LOG_TRAFFIC = True<br>
<br>
# Set up the Twisted application<br>
application = service.Application("Ping Component")<br>
<br>
router = component.Router()<br>
pingComponent = component.Component(EXT_HOST, EXT_PORT, DOMAIN, SECRET)<br>
pingComponent.logTraffic = LOG_TRAFFIC<br>
pingComponent.setServiceParent(application)<br>
<br>
pingHandler = PingHandler()<br>
pingHandler.setHandlerParent(pingComponent)<br>
<br>
produces the following traceback:<br>
<br>
2010-03-03 19:24:28+0100 [XmlStream,0,127.0.0.1] Unhandled Error<br>
Traceback (most recent call last):<br>
File<br>
"\proj\Python-2.5.2\stackless-2.5.2-r63812\Modules\pyexpat.c", line 656,<br>
in EndElement<br>
("(N)", string_intern(self, name)))<br>
File "C:\proj\twisted\twisted\words\xish\domish.py", line<br>
797, in _onEndElement<br>
self.ElementEvent(self.currElem)<br>
File "C:\proj\twisted\twisted\words\xish\xmlstream.py", line<br>
107, in onElement<br>
self.dispatch(element)<br>
File "C:\proj\twisted\twisted\words\xish\utility.py", line<br>
317, in dispatch<br>
callbacklist.callback(obj)<br>
--- <exception caught here> ---<br>
File "C:\proj\twisted\twisted\words\xish\utility.py", line<br>
107, in callback<br>
methodwrapper(*args, **kwargs)<br>
File "C:\proj\twisted\twisted\words\xish\utility.py", line<br>
27, in __call__<br>
self.method(*nargs, **nkwargs)<br>
File<br>
"C:\proj\twisted\twisted\words\protocols\jabber\component.py", line 171,<br>
in onElement<br>
self.onHandshake(unicode(element))<br>
File<br>
"C:\proj\twisted\twisted\words\protocols\jabber\component.py", line 187,<br>
in onHandshake<br>
unicode(self.secret))<br>
File<br>
"C:\proj\twisted\twisted\words\protocols\jabber\xmlstream.py", line 52,<br>
in hashPassword<br>
raise TypeError("The session identifier must be a unicode<br>
object")<br>
exceptions.TypeError: The session identifier must be a unicode<br>
object<br>
<br>
After some fiddling around it seems that the code at line 282 in<br>
twisted\words\protocols\jabber\xmlstream.py presets the sid of the<br>
stream to a str instead of a unicode(str). After changing line 282<br>
from<br>
<br>
self.xmlstream.sid = randbytes.secureRandom(8).encode('hex')<br>
<br>
to<br>
<br>
self.xmlstream.sid = unicode(randbytes.secureRandom(8).encode('hex'))<br>
<br>
everything works as advertised.<br>
<br>
Is there somebody around who could tell me what to do with this fix, I'm<br>
certainly a beginner diddling with XMPP.<br>
<br>
Thanks a bunch, Werner<br>
<br><br>
</blockquote></div><br><br><div>Hello Werner,</div><div><br></div><div>I do not know anything about twisted.words, but you should file a bug report in trac: </div><div><br clear="all"><a href="http://twistedmatrix.com/trac/report">http://twistedmatrix.com/trac/report</a></div>
<div><br>Just out of curiosity, I did look at xmlstream and the whole unicode type checking seems unnecessary considering how the values are used:</div><div><br></div><div>input = u"%s%s" % (sid, password)</div>
<div><br></div><div>Why sid and password have to be unicode objects and not just basestring beats me.</div><div><br></div><div>-Drew</div>