通过 Python 发送消息 + xmpppy:最小示例中的 AttributeError
我在一个相关问题中找到了一个通过 xmpp(py) 发送消息的最小示例;见下文。但是当我执行脚本时,出现以下错误:
client = xmpp.Client('gmail.com')
AttributeError: 'module' object has no attribute 'Client'
我正在使用 Eclipse 和 PyDev,并且肯定应该安装 xmpppy。解释器包括 /usr/local/lib/python2.7/dist-packages/ ,当我查看那里时,我发现
/usr/local/lib/python2.7/dist-packages/xmpppy-0.5.0rc1-py2.7.egg
/usr/local/lib/python2.7/dist-packages/xmpppy-0.5.0rc1-py2.7.egg/xmpp
help('modules') 还向我显示了 xmpp 模块。当在 Eclipse/PyDev 中使用自动完成功能(CTRL + SPACE)时,我实际上可以“看到”客户端。尽管如此,我还是得到了 AttributeError 。我想我在这里错过了一些非常愚蠢的东西。
谢谢,
克里斯蒂安
import xmpp
username = 'username'
passwd = 'password'
to='[email protected]'
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)
I found in a related question a minimal example to send a message via xmpp(py); see below. But when I execute the script I get the following error:
client = xmpp.Client('gmail.com')
AttributeError: 'module' object has no attribute 'Client'
I'm working with Eclipse and PyDev, and xmpppy should definitely be installed. The Interpreter includes /usr/local/lib/python2.7/dist-packages/ and when looking there I find
/usr/local/lib/python2.7/dist-packages/xmpppy-0.5.0rc1-py2.7.egg
/usr/local/lib/python2.7/dist-packages/xmpppy-0.5.0rc1-py2.7.egg/xmpp
help('modules') also shows me the xmpp module. When using the autocomplete function (CTRL + SPACE) in Eclipse/PyDev I can actually 'see' the client. Still, I get the AttributeError. I guess I'm missing something really stupid here.
Thanks,
Christian
import xmpp
username = 'username'
passwd = 'password'
to='[email protected]'
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将脚本命名为
xmpp.py
。您不小心导入
它而不是真正的xmpp
模块。重命名脚本,一切都会正常。
You've named a script
xmpp.py
. You're accidentallyimport
ing it instead of the realxmpp
module.Rename the script and everything should work fine.