【问题标题】:Create a Moodle user from python application using rest api使用 rest api 从 python 应用程序创建一个 Moodle 用户
【发布时间】:2019-11-02 06:44:35
【问题描述】:

我正在尝试使用 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]": "abc@gmail.com"}

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

谁能帮我解决这个问题?

【问题讨论】:

  • 首先尝试将状态打印为 response.status_code,然后如果它不是以 2XX 开头,那么它是您这边的错误。请在此处粘贴 status_code。
  • @pavan,我已经打印了状态码。它的 200。参数也与moodle API文档中提到的完全相同。
  • 我很抱歉,我教这是一个错误的要求。我不知道 Moodle。我认为您可以在 moodle.org/mod/forum/index.php?id=5 中发布您的问题。谢谢。

标签: python rest web-services moodle


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-01-27
    • 2021-07-04
    • 1970-01-01
    • 2016-07-22
    • 2013-07-08
    • 2015-12-29
    • 2016-02-06
    • 1970-01-01
    • 2011-07-20
    相关资源
    最近更新 更多