stillhq.com : Mikal, a geek from Canberra living in Silicon Valley (no blather posts) http://www.stillhq.com The life, times, travel and software of Michael Still (no blather posts) en Copyright (c) Michael Still 2000 - 2006 blosxom simplerss20 v20050208hh 180 http://blogs.law.harvard.edu/tech/rss Getting Google Talk working with PyXMPP /google/gtalk Sun, 19 Nov 2006 16:54:00 GMT Jacek Konieczny has written the wholly fantabulous <a href="http://pyxmpp.jajcus.net/">PyXMPP</a>, which implements Jabber clients and servers in Python. Now, Google Talk is a Jabber server, but it needs TLS support before it works. The code is all there, but the echobot example in <a href="http://pyxmpp.jajcus.net/downloads/pyxmpp-1.0.0.tar.gz">the download</a> (look in the examples directory) doesn't show you how. It's not that hard though -- here's the patch I needed to make it work: <br/><br/> <ul><pre> --- echobot.py 2005-12-26 07:25:55.000000000 -0800 +++ echobot2.py 2006-10-25 04:25:02.000000000 -0700 @@ -13,6 +13,7 @@ from pyxmpp.all import JID,Iq,Presence,Message,StreamError from pyxmpp.jabber.client import JabberClient +from pyxmpp import streamtls class Client(JabberClient): """Simple bot (client) example. Uses `pyxmpp.jabber.client.JabberClient` @@ -28,8 +29,12 @@ # setup client with provided connection information # and identity data + + tls = streamtls.TLSSettings(require=True, verify_peer=False) + auth = ['sasl:PLAIN'] JabberClient.__init__(self, jid, password, - disco_name="PyXMPP example: echo bot", disco_type="bot") + disco_name="PyXMPP example: echo bot", disco_type="bot", + tls_settings=tls, auth_methods=auth) # register features to be announced via Service Discovery self.disco_info.add_feature("jabber:iq:version") </pre></ul> <br/><br/> That makes the __init__ method for the client: <br/><br/> <ul><pre> def __init__(self, jid, password): # if bare JID is provided add a resource -- it is required if not jid.resource: jid=JID(jid.node, jid.domain, "Echobot") # setup client with provided connection information # and identity data tls = streamtls.TLSSettings(require=True, verify_peer=False) auth = ['sasl:PLAIN'] JabberClient.__init__(self, jid, password, disco_name="PyXMPP example: echo bot", disco_type="bot", tls_settings=tls, auth_methods=auth) # register features to be announced via Service Discovery self.disco_info.add_feature("jabber:iq:version") </pre></ul> <br/><br/> Now the client works with a gtalk login: <br/><br/> <ul><pre> $ <b>./echobot2.py username@gmail.com supersecretthingie</b> creating client... connecting... *** State changed: resolving srv (u'gmail.com', 'xmpp-client') *** *** State changed: resolving 'talk.l.google.com.' *** *** State changed: connecting ('72.14.253.125', 5222) *** *** State changed: connected ('72.14.253.125', 5222) *** looping... *** State changed: tls connecting <JID: u'gmail.com'> *** *** State changed: tls connected <JID: u'gmail.com'> *** *** State changed: fully connected <JID: u'gmail.com'> *** *** State changed: authenticated <JID: u'username@gmail.com/Echobot'> *** *** State changed: binding u'Echobot' *** *** State changed: authorized <JID: u'username@gmail.com/EchobotE50E6B7B'> *** mikalstill@gmail.com/Gaim6734F991 has become available mikalstill@gmail.com/GaimD2ECF56B has become available(away): I'm not at my desk at work at the moment. This is probably because I'm at a meeting or racing electric scooters. If you IM me I will see the message when I get back. My roster: mikalstill@gmail.com "" subscription=both groups= Message from mikalstill@gmail.com/Gaim6734F991 received. Body: "Hello there". Type: "chat". disconnecting... exiting... $ </pre></ul> <br/><br/> Too easy. <br/><br/> <i>Update:</i> <a href="/mbot/">mbot</a> is a Google Talk bot engine built on top of this.</i> <br/><br/><i>Tags for this post: google(<a href="http://www.stillhq.com/google"><img src="http://www.stillhq.com/tagicon.cgi?post=/google/gtalk/000001&tag=google&format=.png" border="0" alt="S"></a>) gtalk(<a href="http://www.stillhq.com/gtalk"><img src="http://www.stillhq.com/tagicon.cgi?post=/google/gtalk/000001&tag=gtalk&format=.png" border="0" alt="S"></a>) </i> <br/><br/> <a href="http://www.stillhq.com/google/gtalk/000001.commentform.html">Comment</a> http://www.stillhq.com/google/gtalk/000001.html http://www.stillhq.com/google/gtalk/000001.html