Is there a python ejabberd library?

Is there a python ejabberd library in which I can programmatically register a user on ejabberd from python?

I am currently executing the "ejabberdctl register" command using the python command module.

+8
python ejabberd
source share
2 answers

XMPP XEP-0077

If you activated mod_register to Register in a group on your Ejabberd server, then, as @Drake points out, you can use the XMPP library to register users.

In Python, I would recommend Sleek XMPP . Startup examples are a good starting point.

HTTP

If you activated mod_register_web , you can send an 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 parameter seems to be the β€œAdd User” line.

Assuming you have an ejabberd admin user called user and with password password , using the request HTTP library for Python, you can 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 
+11
source share

ejabberd is a Jabber / XMPP instant messaging server. This means that you can use any XMPP module, for example xmppy .

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

+3
source share

All Articles