如何使用xmpppy向Jabber客户端发送消息?

2024-03-29 11:23:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须发送基于xmpp的聊天客户端(hipchat),为此我使用xmpp.py。目前,我正在尝试从shell发送消息。以下是我从shell执行的语句:

>>> import xmpp
>>> jid = xmpp.protocol.JID('99999_9999@chat.hipchat.com')
>>> cl=xmpp.Client(jid.getDomain(),debug=[])
>>> cl.connect()
'tls'
>>> cl.auth(jid.getNode(),'password')
'sasl'
>>> cl.send(xmpp.protocol.Message('99999_9999@chat.hipchat.com','hey!'))
'3'

我使用相同的jabber身份验证和接收器。我也在聊天室上网,但我没有收到任何信息。少了什么?在


Tags: pyimportcomclient消息客户端clchat
2条回答

我缺少typ参数。将其与值chat相加解决了问题:

cl.send(xmpp.protocol.Message('99999_9999@chat.hipchat.com','hey!', typ='chat'))

一些旧的XMPP服务器需要初始状态。 在cl.send之前使用以下调用发送状态:

cl.SendInitPresence(requestRoster=0)

另请参见xmppy主页中的xsend示例: http://xmpppy.sourceforge.net/examples/xsend.py

相关问题 更多 >