Is there an ejabberd python library wherein I can register user to ejabberd from python programmatically?
开发者_如何学CRight now I'm executing "ejabberdctl register" command using the python commands module.
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
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?.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论