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