Python, xmpppy zapisanie kontaktu do Rostera

0

Witam. Mam taki oto kod:

#!/usr/bin/env python
import sys,os,xmpp,time

jid=xmpp.protocol.JID('[email protected]')
cl=xmpp.Client(jid.getDomain(),debug=[])

con=cl.connect()
if not con:
    print 'could not connect!'
    sys.exit()
print 'connected with',con

auth=cl.auth(jid.getNode(),'password',resource=jid.getResource())
if not auth:
    print 'could not authenticate!'
    sys.exit()
print 'authenticated using',auth

cl.sendInitPresence()

time.sleep(1)

roster=xmpp.roster.Roster().getRoster()
print roster

cl.disconnect()

 

Jest to kod przykladu (przerobiony) z http://xmpppy.sourceforge.net/examples/xsend.py

Próbuję pobrać roster przez:

roster=xmpp.roster.Roster().getRoster() 

ale dostaję błąd:

connected with tls
authenticated using sasl
Traceback (most recent call last):
  File "./xsend.py", line 30, in <module>
    roster=xmpp.roster.Roster().getRoster()
  File "/usr/lib/python2.7/site-packages/xmpp/roster.py", line 60, in getRoster
    if not self.set: self.Request()
  File "/usr/lib/python2.7/site-packages/xmpp/roster.py", line 55, in Request
    self._owner.send(Iq('get',NS_ROSTER))
AttributeError: Roster instance has no attribute '_owner'
 

Co robię źle ?

0

Rozwiązane:

trzeba skorzystać z klasy xmpp.client.Client a nie xmpp.roster.Roster. Przynajmniej u mnie działa. Fragment kodu:

cl=xmpp.Client(jid.getDomain(),debug=[])
ros=cl.getRoster() #Zwraca instancję klasy Roster więc ros od teraz ma te same metody co w xmpp.roster.Roster
wynik=ros.getName("[email protected]")
print wynik
 

1 użytkowników online, w tym zalogowanych: 0, gości: 1