Catch Invisible Friends On GTalk The Python Way

Google-TalkEver wanted to know that someone is really offline or has just gone invisible in GTalk? Here is a small trick. The bellow peace of python code get the list of invisible users from your GTalk buddy list. It uses XMPP module for python. You can install this module in Ubuntu/Debian via apt. It also requires python dns module.

$ sudo aptitude install python-xmpp python-dnspython

Now here is our script. Open your favorite text editor and save the code as ‘’. Dont forget to fill your gtalk username and password in the script.

import xmpp
# Google Talk constants
GMAIL_PASS = "secret"
if not C.connect((GTALK_SERVER,5222)):
    raise IOError('Can not connect to server.')
if not C.auth(jid.getNode(),GMAIL_PASS):
    raise IOError('Can not auth with server.')
def myPresenceHandler(con, event):
   if event.getType() == 'unavailable':
     print event.getFrom().getStripped()
C.RegisterHandler('presence', myPresenceHandler)
while C.Process(1):

Now simply run:

$ python

So , Next time do not let anyone fool you , rather catch him Invisibly .


maquinadecafe September 2, 2010

Nice trick. I’ll give it a try. Cheers !

maquinadecafe September 5, 2010

Hi, im getting this error when running the script:

$ python
File “”, line 24
raise IOError(‘Can not connect to server.’)
IndentationError: expected an indented block

I’ve made the file executable, and also tried to run it as root. Can you give some help ? Thanks

maquinadecafe September 5, 2010

Hi… me again. Seems like i copied/pasted it and gave a bad format to the text. Now the script runs, … BUT this is what i get:
$ python
/usr/lib/python2.6/dist-packages/xmpp/ DeprecationWarning: the sha module is deprecated; use the hashlib module instead
import sha,base64,random,dispatcher,re
/usr/lib/python2.6/dist-packages/xmpp/ DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5
/usr/lib/python2.6/dist-packages/xmpp/ DeprecationWarning: socket.ssl() is deprecated. Use ssl.wrap_socket() instead.
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)

And stands there, and does nothing for as long i let it.

If i do CTRL+C to abort the execution:

Traceback (most recent call last):
File “”, line 23, in
while C.Process(1):
File “/usr/lib/python2.6/dist-packages/xmpp/”, line 119, in Process
if self._owner.Connection.pending_data(timeout):
File “/usr/lib/python2.6/dist-packages/xmpp/”, line 302, in pending_data
return self._tcpsock._seen_data or[self._tcpsock._sock],[],[],timeout)[0]

The same happens if i run it as root. Am i missing something ?
Thank you for your help.

Scott December 21, 2010

did any one ever find a proper work around? there is clearly something wrong with auth, google probably updated something… but I am having the same problem described above…

Vimal February 15, 2011

I used this code snippet earlier and it worked. But now it doesn’t seem to work in any python versions.