views:

365

answers:

2

Hi there,

I'm trying to access my google talk contacts' custom status messages with xmpppy. I'm made it this far:

import xmpp
import sys

userID   = '[email protected]' 
password = 'mypassword'
ressource = 'Script'

jid  = xmpp.protocol.JID(userID)
jabber  = xmpp.Client(jid.getDomain(), debug=[])

connection = jabber.connect(('talk.google.com',5222))
auth = jabber.auth(jid.getNode(), password, ressource)

jabber.sendInitPresence(requestRoster=1)
myroster = jabber.getRoster()

the roster object myroster now contains my contacts, but the custom status message is not included.

myroster.getStatus('[email protected]')

returns None

looking at the 'raw roster', I can see that the resources dictionary is empty

u'[email protected]': {'ask': None, 'resources': {}, 'name': u'Some Name', 'groups': [], 'subscription': u'both'}

The weird thing is that I have gotten this to work today, but I the code might have been slightly different, but I can't figure out what exactly I did differently...

Any help would be greatly appreciated!

Cheers,

Martin

+1  A: 

It's a timing issue. Add a handler with:

jabber.RegisterHandler('presence', myPresenceHandler)

def myPresenceHandler(self, con, event):
  fromjid = event.getFrom().getStripped()
  status = myroster.getStatus(fromjid)

BEFORE connecting. Then make sure to call jabber.Process() in a loop. The issue is that with your code, you'll sometimes receive presence stanzas before you look at the roster object, and sometimes after.

Joe Hildebrand
+1  A: 

Here's one thing I've found, which was not clear to me when I first started working with xmpp. Friending is two-way.

Using presence stanzas
(a) You can "subscribe" to your friend, and your friend can return "subscribed".
(b) Your friend can "subscribe" to you, and you can return "subscribed".

Your friend will be in your roster if either (a) or (b) has happened.
You will be in your friends roster if either (a) or (b) has happened.

However...
You will not see their status unless you "subscribe" to your friend - (a) must happen
They will not see your status unless they "subscribe" to you - (b) must happen.

Most XMPP clients (pidgin, trillian, etc) will automatically make you send "subscribe" back to your friend when you send them "subscribed" (after they've sent you "subscribe"). XMPPPY does not do this out of the box. You must code it to do this.

This could explain why you weren't seeing status. Or if this doesn't cover your situation, it might be informative to someone else.

David Gregory
Hi David, though I haven't applied your information yet, I appreciate you proving this answer. I'll post another comment once I know if this was the cause of the problem. cheers! martin
Hoff