使用rest api从python应用程序创建一个Moodle用户



我正试图使用rest api从我的python应用程序创建一个Moodle用户,但出现异常"检测到无效的参数值(单个结构中缺少必需的键:课程("one_answers"单一结构中缺少必需的关键字:课程"。

我正在使用所需的参数进行一个简单的请求调用。我的代码如下:

import request
token = "xxxxxxxxxx"
function='core_user_create_users'
url = 'http://localhost/webservice/rest/server.php?wstoken={0}&wsfunction={1}&moodlewsformat=json'.format(token,function)
users = {
"users[0][createpassword]": 1,
"users[0][username]": "testuser2",
"users[0][auth]": "manual",
"users[0][firstname]": "test2",
"users[0][lastname]": "lastname_test2",
"users[0][email]": "abc@gmail.com"}
response= requests.post(url,json=users)
print(response.content)

有人能帮我解决这个问题吗?

有一个名为moodle moosh的库(https://moosh-online.com/),可以在linux上使用命令行创建用户,非常适合python。

最新更新