Howto to Talk with GoogleTalk in Python

I guess everybody know GoogleTalk right now. Linux users like me knows that it ‘s only a Jabber server with SIP extension. Like a lot of people seems to use this, I decided to switch from MSN(suxTm) to this Jabber server, beside it lacks a lot of Jabber features (like offline messaging )

But, how can I send a message to my Gmail Talk in less 10 lines of code. I decided to look at xmpppy .. Ok I get a strange issue w/ secure login ..

As I already use gajim, I decided to look at this code.. Hum, look strange it has the same xmpp module, with the same API, but this one is working.

import xmpp

login = 'Your.Login' # @gmail.com
pwd   = 'YourPassword'

cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )

cnx.auth(login,pwd, 'botty')

cnx.send( xmpp.Message( "YourFriend@gmail.com" ,"Hello World form Python" ) )

As you can see this is small and simple :) The only issue is to find the right module, and hope the xmpppy will fix that soon.

(In fact gajim team seems to fork the xmpp code due to lack of support. This bug already exists in the xmpppy bug list )



Related Posts

22 thoughts on “Howto to Talk with GoogleTalk in Python

  1. On yes, it’s Jabber + InDoor_Not_Public_Yet_P2P_VOIP, you’re right.. But anyways, I guess not a lot of people will use this VOIP provider right now.

  2. Perhaps it’s time to merge no ? 3 modules w/ quite the same API..

    As usual in Python world, divide to loose :(

  3. dev of xmpppy does have time/interest to maintain it anymore. Hopefully someone else will go to apply our (as in Gajim) patches as eventhough we were asking him to do so when we were commiting he thought our patches were something like testing for his stable (!) xmpppy..

    apart from PyXMPP there is also xmpp in twisted but it lives in 2000

  4. in fact, he wants to maintain the library but he doesn’t have the time and he hopes he sometime later or someone else will apply our patches to cvs. he doesn’t plan to release anytime soon neither unfortunately.

  5. Hello. I’m the maintainer of xmpppy library. I was out for holidays so probably feeled quite unresponsive.
    I’ll patch this bug.
    What for words of Nikos – I have never said about stopping maintaing library. Last 6 months I had not wrote any new code but was regularly fixing bugs and intending to do that in future.

  6. Better example code might have been something that works. Your code errors with:

      File “/usr/lib/python2.4/site-packages/xmpp/auth.py”, line 139, in FeaturesHandler

        sasl_data=’%sx00%sx00%s’%(self.username+’@'+self._owner.Server,self.username,self.password)

    AttributeError: SASL instance has no attribute ‘username’

    Indeed, xmpppy appears so riddled with bugs, none of its “sample” scripts work either. I can see why the dev abandoned it. After several minutes trying to fix its bugs, I quickly discovered a having root-canal would be more fun. Please developers, ensure your code from CVS works before releasing it.

  7. How can I use this to get my domain (domain.com for the sake of security) hosted at google gtalk account working? I’ve tried to no avail –

    import xmpp

    login = ‘user@domain.com’ # @gmail.com
    pwd = ‘password’

    cnx = xmpp.Client(‘domain.com’)
    cnx.connect( server=(‘talk.google.com’,5223) )
    cnx.auth(login,pwd, ‘botty’)

    cnx.send( xmpp.Message( “paul@domain.com” ,”Hello World form Python” ) )

  8. @ Paul Pasika:
    Try this:
    import xmpp
    login = ‘user’ #no @ domain.com
    pwd = ‘pass’

    connection = xmpp.Client(‘Domain.com’)
    connection.connect(server=(‘talk.google.com’,5222))
    connection.auth(login,pwd,”Bot”)

  9. Hi,

    Nice example. I’m getting duplicate messages on my Motorola Droid when I use this method. I’m not sure whether it is the Android Gtalk Client or this method or some interaction of the two. When I send messages using xmpppy they are not duplicated in the Windows Gtalk Window. Messages are not duplicated when they are not sent with xmpppy. Just wondering if anyone had any idea what was going on. This is my first interaction with xmpp.

    Thanks,
    Roger

  10. I’ve discovered that when no resource identifier is provided for the sender, I receive double message with the Android client. When I use the resource identifier of my phone, which I obtained with Pidgin, I receive single posts as I should. So that is a work around if anyone stumbles on to the same problem.

  11. hello friends, this is very awsome, i tested it under python 2.0.0 on my nokia n97 mini and it works awsome.
    hope will figure how to develop more advanced application.:D

    best regards and thanx for this

    wook

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>