使用 python 库发送 xmpp 消息 [英] Send an xmpp message using a python library
问题描述
如何使用以下 Python 库之一发送 XMPP 消息:wokkel、xmpppy 或 jabber.py?
How can I send an XMPP message using one of the following Python libraries: wokkel, xmpppy, or jabber.py ?
我想我知道伪代码,但到目前为止还没有能够正确运行.这是我迄今为止尝试过的:
I think I am aware of the pseudo-code, but so far have not been able to get one running correctly. This is what I have tried so far:
- 调用一些 API 并传递服务器名和端口号以连接到该服务器.
- 调用一些 API 并传递用户名、密码来构造 JID 对象.
- 使用该 JID 进行身份验证.
- 构造一个 Message 对象并调用一些 API 并在参数中传递该消息 obj.
- 调用一些发送 API.
这在概念上似乎很容易,但细节却是魔鬼.如果可能,请显示示例代码段.
It seems easy enough in concept, but the devil is somewhere in the details. Please show a sample snippet if that's possible.
推荐答案
这是最简单的 xmpp 客户端.它将发送一个你好:)"消息.我在示例中使用 xmpppy
.并连接到 gtalk 服务器.我认为这个例子是不言自明的:
This is the simplest possible xmpp client. It will send a 'hello :)' message. I'm using xmpppy
in the example. And connecting to gtalk server. I think the example is self-explanatory:
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)
这篇关于使用 python 库发送 xmpp 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!