开发者

Sending message via Python + xmpppy: AttributeError in minimal example

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 actual开发者_开发百科ly '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='name@example.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)


You've named a script xmpp.py. You're accidentally importing it instead of the real xmpp module.

Rename the script and everything should work fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜