Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用RESTAPI从python应用程序创建Moodle用户_Python_Rest_Web Services_Moodle - Fatal编程技术网

使用RESTAPI从python应用程序创建Moodle用户

使用RESTAPI从python应用程序创建Moodle用户,python,rest,web-services,moodle,Python,Rest,Web Services,Moodle,我试图使用RESTAPI从python应用程序创建Moodle用户,但遇到异常 “检测到无效的参数值(单个结构中缺少必需的键:课程)”和 “单一结构中缺少必需的键:课程” 我正在用所需的参数进行一个简单的请求调用。我的代码如下: import request token = "xxxxxxxxxx" function='core_user_create_users' url = 'http://localhost/webservice/rest/server.ph

我试图使用RESTAPI从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]": "abc@gmail.com"}

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

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

有一个名为moodle moosh()的库,它可以在linux上使用命令行创建用户,非常适合python。

有一个名为moodle moosh()的库,它可以在linux上使用命令行创建用户,非常适合python。

首先尝试将状态打印为response.status\u代码,然后如果它不是以2XX开头的,那么它就是您这边的错误。请将状态码粘贴到这里。@pavan,我已经打印了状态码。200美元。参数也和moodle API文档中提到的完全相同。很抱歉,我教过这是一个错误的请求。我不知道Moodle。我想你可以把你的问题发到网上。谢谢。首先尝试将状态打印为response.status_代码,然后如果它不是以2XX开头的,那么它是您这边的错误。请将状态码粘贴到这里。@pavan,我已经打印了状态码。200美元。参数也和moodle API文档中提到的完全相同。很抱歉,我教过这是一个错误的请求。我不知道Moodle。我想你可以把你的问题发到网上。谢谢