[Twisted-Python] twisted xmpp-router component interface problem

Werner Thie wthie at thiengineering.ch
Wed Mar 3 13:56:38 EST 2010


Hi

Starting twistd xmpp-router and trying to connect to it with a component 
from the wokkel examples

"""
An XMPP Ping server as an external server-side component.

This ping server assumes the domain C{'ping'}.
"""
import sys

from twisted.python import log
from twisted.application import app, service, internet
from twisted.internet import reactor

from wokkel import component
from wokkel.ping import PingHandler

# Configuration parameters
EXT_HOST = 'localhost'
EXT_PORT = 5347
SECRET = 'secret'
DOMAIN = 'ping'
LOG_TRAFFIC = True

# Set up the Twisted application
application = service.Application("Ping Component")

router = component.Router()
pingComponent = component.Component(EXT_HOST, EXT_PORT, DOMAIN, SECRET)
pingComponent.logTraffic = LOG_TRAFFIC
pingComponent.setServiceParent(application)

pingHandler = PingHandler()
pingHandler.setHandlerParent(pingComponent)

produces the following traceback:

2010-03-03 19:24:28+0100 [XmlStream,0,127.0.0.1] Unhandled Error
         Traceback (most recent call last):
           File 
"\proj\Python-2.5.2\stackless-2.5.2-r63812\Modules\pyexpat.c", line 656, 
in EndElement
             ("(N)", string_intern(self, name)))
           File "C:\proj\twisted\twisted\words\xish\domish.py", line 
797, in _onEndElement
             self.ElementEvent(self.currElem)
           File "C:\proj\twisted\twisted\words\xish\xmlstream.py", line 
107, in onElement
             self.dispatch(element)
           File "C:\proj\twisted\twisted\words\xish\utility.py", line 
317, in dispatch
             callbacklist.callback(obj)
         --- <exception caught here> ---
           File "C:\proj\twisted\twisted\words\xish\utility.py", line 
107, in callback
             methodwrapper(*args, **kwargs)
           File "C:\proj\twisted\twisted\words\xish\utility.py", line 
27, in __call__
             self.method(*nargs, **nkwargs)
           File 
"C:\proj\twisted\twisted\words\protocols\jabber\component.py", line 171, 
in onElement
             self.onHandshake(unicode(element))
           File 
"C:\proj\twisted\twisted\words\protocols\jabber\component.py", line 187, 
in onHandshake
             unicode(self.secret))
           File 
"C:\proj\twisted\twisted\words\protocols\jabber\xmlstream.py", line 52, 
in hashPassword
             raise TypeError("The session identifier must be a unicode 
object")
         exceptions.TypeError: The session identifier must be a unicode 
object

After some fiddling around it seems that the code at line 282 in 
twisted\words\protocols\jabber\xmlstream.py presets the sid of the 
stream to a str instead of a unicode(str). After changing line 282
from

self.xmlstream.sid = randbytes.secureRandom(8).encode('hex')

to

self.xmlstream.sid = unicode(randbytes.secureRandom(8).encode('hex'))

everything works as advertised.

Is there somebody around who could tell me what to do with this fix, I'm 
certainly a beginner diddling with XMPP.

Thanks a bunch, Werner





More information about the Twisted-Python mailing list