【问题标题】:Subscribing new recipient: update_roster() seems to hang订阅新收件人:update_roster() 似乎挂起
【发布时间】:2017-12-14 02:12:30
【问题描述】:

我有一个小的 python 脚本可以将 xmpp 消息发送给给定的收件人。如果收件人已有订阅,则此方法效果很好 - 否则消息将不会被传递。

由于系统定期有新用户,我想到了使用update_roster(recipient,block=False,subscription="both") 自动订阅新收件人的想法。但不幸的是,脚本似乎挂在那里。

为什么?

在下面查看我的代码...

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)

【问题讨论】:

    标签: python xmpp sleekxmpp


    【解决方案1】:

    好的,显然我自己解决了这个问题。将 subscription="both" 更改为 subscription="to" - 所以声明如下所示:

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

    :-)

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 2016-05-15
      • 1970-01-01
      • 2020-01-01
      相关资源
      最近更新 更多