Is there an ejabberd python library?

风流意气都作罢 提交于 2019-12-04 11:00:43

问题


Is there an ejabberd python library wherein I can register user to ejabberd from python programmatically?

Right now I'm executing "ejabberdctl register" command using the python commands module.


回答1:


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



回答2:


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?.



来源:https://stackoverflow.com/questions/5141462/is-there-an-ejabberd-python-library

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