Is there an ejabberd python library?

怎甘沉沦 提交于 2019-12-03 06:52:42

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
Drake Guan

ejabberd is a Jabber/XMPP instant messaging server. That means you can make use of any XMPP module, like xmppy.

Also, check this thread: Which is the most mature Python XMPP library for a GChat client?.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!