sers
sers

Reputation: 3659

Subscribing new recipient: update_roster() seems to hang

I've got a small python script to send xmpp-messages to a given recipient. This works well, if there's an existing subscription for the recipient - otherwiese the message won't be delivered.

As there are new users to the system regularly, I had the idea to automatically subscribe the new recipients using update_roster(recipient,block=False,subscription="both"). But unfortunately the script seems to hang there.

Why?

See my code below ...

class SendMsgBot(sleekxmpp.ClientXMPP):

  def __init__(self, jid, password, recipient, message):
    sleekxmpp.ClientXMPP.__init__(self, jid, password)

    self.recipient = recipient
    self.msg = message

    self.add_event_handler("session_start", self.start)

  def start(self, event):
    self.send_presence()
    self.get_roster()
    if self.msg =="":
      # HERE IT IS ....
      self.update_roster(recipient,block=False,subscription="both")
    else:
      self.send_message(mto=self.recipient,
                        mbody=self.msg,
                        mtype='chat')

    self.disconnect(wait=True)

Upvotes: 0

Views: 51

Answers (1)

sers
sers

Reputation: 3659

Ok, apparently I just solved this myself. Changed subscription="both" to subscription="to" - so the statement looks like this:

     self.update_roster(recipient,block=False,subscription="to")

:-)

Upvotes: 0

Related Questions