Closed zyfmix closed 8 years ago
Hi zyfmix, looks like your python script test register
command rather then check_account
. Keep in mind that some commands from ejabberd rpc module require special grants from user executing them. You can execute register
with any credentials you want, but check_account
require special grants from ejabberd server.
Now, this library designed as ejabberd grants all to executing rpc calls. Please could you chech check_account
with python script?
Thank you for your reply.I just test check_accout with my python code below:
server_url = 'http://42.96.194.60:4560'
server = xmlrpclib.ServerProxy(server_url)
EJABBERD_XMLRPC_LOGIN = {'user': 'zyf', 'server': 'coopens.com', 'password': '123456'} # , 'token': 'k1iTItUPDgH9NB4yTFYyTttRtNIlHjyV'
def ejabberdctl(command, data):
fn = getattr(server, command)
return fn(EJABBERD_XMLRPC_LOGIN, data)
result = ejabberdctl('check_account', {'user':'zyfer', 'host':'coopens.com'})
print result
it just return
{'res': 0}
but when it test with an non exist user account it return:
{'res': 1}
The result seem to be wrong,but it does't crashed.
The difference is you call RPC command with credentials in python. Curently this library not support this. But you are wellcome to add this feature - just need to pass user/password to RpcClient constructor arguments and extends params of sendRequest
method with this.
I think we can do this (if you have no time) in nearest 2-3 weeks.
The Python auth admin user by code below:
@property
def auth(self):
"""
Returns a dictionary containing the basic authorization info
:rtype: dict
:return: a dictionary containing the basic authorization info
"""
return {
'user': self.username,
'server': self.user_domain,
'password': self.password
}
and extends param with above auth like below:
response = method(self.auth, arguments)
I was try add admin param to sendRequest like code below:
$request = xmlrpc_encode_request($command,
['user' => 'zyf', 'server' => 'coopens.com', 'password' => '123456'],
$params, ['encoding' => 'utf-8', 'escaping' => 'markup']);
but it test failed,I'm confused with xmlrpc,can you tell me how to extends params to sendRequest?
I have solved it by change sendRequest with code below and working:
$request = xmlrpc_encode_request(
$command,
[['user' => 'zyf', 'server' => 'coopens.com', 'password' => '123456'], $params],
['encoding' => 'utf-8', 'escaping' => 'markup']
);
@misterion : Thank you very much!
I need to check it more, but as i remember it use http basic authorization. So, with curl under the hood:
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
So can you add it as pull resuqest? I mean is user and password specifies in cofig pass it with params on every request.
Thank you for you reply.I have pull request and this question can be closed ^_^
i am runing with ejabberd 15.11 and use the code below:
but it just crash a error:
and i have test python code success:
it seems to have login with admin account to run this function in advance. i dont know how to deal with it,who can help me?