Is there any python xmpp library that supports adding/removing users?

白昼怎懂夜的黑 提交于 2020-01-31 04:02:15

问题


Right now I have a python class that creates user/deletes users by executing "ejabberdctl register/unregister" commands. Is there a python xmpp library that supports adding/removing users?


回答1:


You need to have an implementation of XEP-0077: In-Band Registration. xmpppy does appear to support this:

import sys
import os
import xmpp

if len(sys.argv) < 3:
    print "Syntax: register.py [JID] [Password]"
    sys.exita(64)

jid=xmpp.protocol.JID(sys.argv[1])
cli=xmpp.Client(jid.getDomain(), debug=[])
cli.connect()

# getRegInfo has a bug that puts the username as a direct child of the
# IQ, instead of inside the query element.  The below will work, but
# won't return an error when the user is known, however the register
# call will return the error.
xmpp.features.getRegInfo(cli,
                         jid.getDomain(),
                         #{'username':jid.getNode()},
                         sync=True)

if xmpp.features.register(cli,
                          jid.getDomain(),
                          {'username':jid.getNode(),
                           'password':sys.argv[2]}):
    sys.stderr.write("Success!\n")
    sys.exit(0)
else:
    sys.stderr.write("Error!\n")
    sys.exit(1)



回答2:


xmpppy looks to have all the various methods for manipulating a client's roster.

Never used this myself, but the API documentation for the Roster class lists: delItem(self, jid) and setItem(self, jid) that remove and add the specified jid to the roster.

http://xmpppy.sourceforge.net/

http://xmpppy.sourceforge.net/apidocs/



来源:https://stackoverflow.com/questions/5131982/is-there-any-python-xmpp-library-that-supports-adding-removing-users

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