Using core_user_create_users In Python Script

Using core_user_create_users In Python Script

by Sofiane beni -
Number of replies: 1

Hi,


I'm using Moodle 3.3.1 and in try to create an User withPython Script.

My Moodle web services configuration is good (i think).

But the user is not created, i have no error, nothing, just this line in my Apache logs :

[06/Sep/2017:16:24:32 +0200] "POST /webservice/rest/server.php?wstoken=XXXXXXXXXXX&wsfunction=core_user_create_users&moodlewsformat=json HTTP/1.1" 200 430 "-" "python-requests/2.18.4


Here my Python Script :

#!/bin/python3.6

import requests

token = 'XXXXXXXXXXXXXXX'
function = 'core_user_create_users'

url = 'http://localhost/webservice/rest/server.php?wstoken={0}&wsfunction={1}&moodlewsformat=json'.format(token,function)

users = {'users[0][email]': 'test@mydept.edu',
        'users[0][firstname]': 'Test',
        'users[0][lastname]': 'Test1',
        'users[0][createpassword]': 1,
        'users[0][username]': 'Testst'}
requests.post(url,data=users)


Thank you in advance for your help.

Average of ratings: -
In reply to Sofiane beni

Re: Using core_user_create_users In Python Script

by Dmitry Sher -

Server always returns code 200 (no error for HTTP), but see error description in the response message

response = requests.post(url,data=users)
print(response.json())

No privileges is typical problem IMO