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

问题描述 投票:1回答:1

[我正在尝试使用rest api从我的python应用程序创建Moodle用户,但出现异常“检测到无效的参数值(单个结构中缺少必需的键:课程)”和“在单一结构中缺少所需的关键:课程”。

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

    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]": "[email protected]"}

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

任何人都可以帮助我解决此问题吗?

python rest web-services moodle
1个回答
0
投票
[有一个名为moodle moosh(https://moosh-online.com/)的库,可以在Linux上用命令行创建用户,非常适合python。
© www.soinside.com 2019 - 2024. All rights reserved.