<div class="gmail_quote">On Wed, Mar 3, 2010 at 1:56 PM, Werner Thie <span dir="ltr">&lt;<a href="mailto:wthie@thiengineering.ch">wthie@thiengineering.ch</a>&gt;</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>
&quot;&quot;&quot;<br>
An XMPP Ping server as an external server-side component.<br>
<br>
This ping server assumes the domain C{&#39;ping&#39;}.<br>
&quot;&quot;&quot;<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 = &#39;localhost&#39;<br>
EXT_PORT = 5347<br>
SECRET = &#39;secret&#39;<br>
DOMAIN = &#39;ping&#39;<br>
LOG_TRAFFIC = True<br>
<br>
# Set up the Twisted application<br>
application = service.Application(&quot;Ping Component&quot;)<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>
&quot;\proj\Python-2.5.2\stackless-2.5.2-r63812\Modules\pyexpat.c&quot;, line 656,<br>
in EndElement<br>
             (&quot;(N)&quot;, string_intern(self, name)))<br>
           File &quot;C:\proj\twisted\twisted\words\xish\domish.py&quot;, line<br>
797, in _onEndElement<br>
             self.ElementEvent(self.currElem)<br>
           File &quot;C:\proj\twisted\twisted\words\xish\xmlstream.py&quot;, line<br>
107, in onElement<br>
             self.dispatch(element)<br>
           File &quot;C:\proj\twisted\twisted\words\xish\utility.py&quot;, line<br>
317, in dispatch<br>
             callbacklist.callback(obj)<br>
         --- &lt;exception caught here&gt; ---<br>
           File &quot;C:\proj\twisted\twisted\words\xish\utility.py&quot;, line<br>
107, in callback<br>
             methodwrapper(*args, **kwargs)<br>
           File &quot;C:\proj\twisted\twisted\words\xish\utility.py&quot;, line<br>
27, in __call__<br>
             self.method(*nargs, **nkwargs)<br>
           File<br>
&quot;C:\proj\twisted\twisted\words\protocols\jabber\component.py&quot;, line 171,<br>
in onElement<br>
             self.onHandshake(unicode(element))<br>
           File<br>
&quot;C:\proj\twisted\twisted\words\protocols\jabber\component.py&quot;, line 187,<br>
in onHandshake<br>
             unicode(self.secret))<br>
           File<br>
&quot;C:\proj\twisted\twisted\words\protocols\jabber\xmlstream.py&quot;, line 52,<br>
in hashPassword<br>
             raise TypeError(&quot;The session identifier must be a unicode<br>
object&quot;)<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(&#39;hex&#39;)<br>
<br>
to<br>
<br>
self.xmlstream.sid = unicode(randbytes.secureRandom(8).encode(&#39;hex&#39;))<br>
<br>
everything works as advertised.<br>
<br>
Is there somebody around who could tell me what to do with this fix, I&#39;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&quot;%s%s&quot; % (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>