我正在尝试使用Python发送XMPP消息,但是一直无法成功。似乎在身份验证步骤出现了问题。我从之前的一个问题中引用了这个例子,并设置了一个用于测试的Gmail账号。
import xmpp
username = 'randomtest603@gmail.com'
passwd = 'ThePass123'
to='randomtest604@gmail.com'
msg='hello :)'
client = xmpp.Client('gmail.com')
client.connect(server=('talk.google.com',5223))
client.auth(username, passwd, 'botty')
client.sendInitPresence()
message = xmpp.Message(to, msg)
message.setAttr('type', 'chat')
client.send(message)
有很多调试输出,但这是告诉我它失败的部分。
DEBUG: socket sent <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">cmFuZG9tdGVzdDYwM0BnbWFpbC5jb21AZ21haWwuY29tAHJhbmRvbXRlc3Q2MDNAZ21haWwuY29tAFRoZVBhc3MxMjM=</auth>
DEBUG: socket got <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<invalid-authzid/>
</failure>
</stream:stream>
DEBUG: dispatcher ok Got urn:ietf:params:xml:ns:xmpp-sasl/failure stanza
DEBUG: dispatcher ok Dispatching failure stanza with type-> props-> [u'urn:ietf:params:xml:ns:xmpp-sasl'] id->None
DEBUG: sasl error Failed SASL authentification: <invalid-authzid />
但是最后我也得到了这个信息。
DEBUG: socket sent <presence id="2" />
DEBUG: socket sent <message to="randomtest604@gmail.com" type="chat" id="3">
<body>hello :)</body>
</message>
我尝试过xmpppy和sleekxmpp,结果都一样。由于这个领域对我来说很新,所以可能犯了一些初学者的错误,有人有什么想法吗?
谢谢。