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 :

admin August 31st, 2005


21 Responses to “Howto to Talk with GoogleTalk in Python”

  1. philon 31 Aug 2005 at 9:06 am

    GTalk doesn’t support SIP yet. See the GTalk developer info page

  2. Jkxon 31 Aug 2005 at 10:02 am

    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.

  3. Swaroopon 31 Aug 2005 at 10:41 am

    Interesting.

    Is it this easy to write a spimbot for GTalk?

  4. zgodaon 31 Aug 2005 at 11:48 am

    The most complete XMPP/Jabber library currently in the wild is PyXMPP (http://pyxmpp.jabberstudio.org/). Unfortunately, it is currently supported only on linux platform, though some work is underway to port it to Windows.

  5. Jkxon 31 Aug 2005 at 1:29 pm

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

    As usual in Python world, divide to loose :(

  6. Nikos Kouremenoson 31 Aug 2005 at 3:05 pm

    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

  7. Jonon 31 Aug 2005 at 7:34 pm

    Nice … very useful little snippet.  Thanks!



    Jon – jon_edwards@spanners4us.com

  8. nikos kouremenoson 02 Sep 2005 at 11:26 am

    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.

  9. Alexey Nezhdanovon 02 Sep 2005 at 11:29 am

    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.

  10. Ricon 15 Sep 2005 at 4:15 pm

    J’en pense rien
    C’est juste un test

    ++

  11. Cerinon 06 Oct 2005 at 6:27 am

    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.

  12. Richieon 19 Jul 2007 at 12:39 am

    Two years old. Still very useful :)

  13. LKRaideron 03 May 2008 at 6:47 am

    Can’t get it to work :(

    Is there a better jabber lib for python?

  14. Paul Pasikaon 31 Mar 2009 at 7:53 pm

    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” ) )

  15. K-4Uon 15 Apr 2009 at 5:31 pm

    @ 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”)

  16. Roger Lewon 05 Dec 2009 at 7:02 am

    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

  17. Roger Lewon 05 Dec 2009 at 7:19 pm

    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.

  18. iraj jelodarion 25 Oct 2010 at 8:52 pm

    Hi , very very tanx buT how to send a message to response ?????????????? :O

  19. Migluon 01 Nov 2010 at 11:36 pm

    Hi,

    Checkout http://www.miglu.com

    Its a service which allows low cost international calls directly from your phone.

    It also has a xmpp bot. Add gomiglu@gmail.com to your friends list and try :)

    Regards
    Miglu

  20. wookon 13 Dec 2010 at 4:50 am

    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

  21. Dirk Krauseon 29 Sep 2011 at 2:26 pm

    For some reason this code didn’t work for me – this one did the trick:
    http://www.sakibiqbal.com/2011/programming/sending-google-talk-im-using-python/

    Thanks all the same!

Comments RSS

Leave a Reply