8

是否有一个 ejabberd python 库,我可以在其中以编程方式从 python 注册用户到 ejabberd?

现在我正在使用 python 命令模块执行“ejabberdctl register”命令。

4

2 回答 2

12

XMPP XEP-0077

If you have activated mod_register for In-Band registration on your Ejabberd server, then, as pointed out by @Drake, you can use an XMPP library to register users.

In Python, I would recommend Sleek XMPP. The Getting started examples are, well, a good starting point.

HTTP

If you have activated mod_register_web then you can send a HTTP POST request to http://<SERVERNAME>:5280/admin/server/<VIRTUALHOSTNAME>/users/. This URL expects the following 3 parameters:

  • newusername
  • newuserpassword
  • addnewuser

where the expected value for the addnewuser param seems to be the string "Add User".

Assuming you have an ejabberd admin user called user and with password password, using the requests HTTP library for Python, you could do something like the following:

import requests
from requests.auth import HTTPBasicAuth

server = "NAME OF YOUR EJABBERD SERVER"
virtualhost = "NAME OF YOUR EJABBERD HOST"
url = "http://%s:5280/admin/server/%s/user/" % (server, virtualhost)
auth = HTTPBasicAuth("user", "password")
data = {
    'newusername': "new_user",
    'newuserpassword': "new_password",
    'addnewuser': "Add User"
}
resp = requests.post(url, data=data, auth=auth)


assert resp.status_code == 200
于 2012-06-21T14:39:14.943 回答
3

ejabberd 是一个 Jabber/XMPP 即时消息服务器。这意味着您可以使用任何 XMPP 模块,例如xmppy

另外,请查看此线程:对于 GChat 客户端,哪个是最成熟的 Python XMPP 库?.

于 2011-02-28T12:32:13.377 回答