【问题标题】:Send an XMPP message with Python使用 Python 发送 XMPP 消息
【发布时间】:2013-02-12 22:34:41
【问题描述】:

我正在尝试使用 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 和 slimxmpp,结果是一样的。这个领域对我来说是新的,所以我可能会犯一个新手错误,有人有什么想法吗?

谢谢

【问题讨论】:

  • 你使用的是什么 XMPP 模块?

标签: python xmpp sendmessage


【解决方案1】:

您的问题不是特定于 python 的,也不是特定于库的。当您调用xmpp.Client('gmail.com') 时,您将用户名的域部分指定为“gmail.com”。因此,您应该从您使用的用户名中省略它。

将您的第三行修改为:

username = 'randomtest603'

它应该可以工作(我在为此测试生成应用程序特定密码后用我自己的帐户尝试过它,只有当我从用户名中省略'@gmail.com'时它才有效,否则我会遇到与你相同的错误) .

【讨论】:

  • 很高兴能帮上忙 :)
  • @entropy,我遇到了同样的问题。我已经按照你说的做了,但仍然有这个错误。怎么办..?
  • @Mulagala 在没有看到您的任何代码的情况下无法确定
  • @entropy,代码正是我们在上面看到的问题并按照您所说的进行了编辑
  • 您是否 100% 确定您拥有正确的凭据?因为我不知道你的情况出了什么问题
猜你喜欢
  • 2010-10-28
  • 1970-01-01
  • 2013-10-28
  • 2011-05-31
  • 1970-01-01
  • 2019-09-06
  • 2011-05-18
  • 1970-01-01
  • 2015-08-24
相关资源
最近更新 更多