Python request.post缺少必需的参数

时间:2018-06-18 18:35:24

标签: python request

我一直在四处寻找并试图找到工作要求,但我没有找到任何运气。每次发出请求时我都会收到MISSING_REQUIRED_PARAM。我的以下代码如下所示。

def create_sign_group(group_name, header, url):

    temp_header = header
    temp_header['Content-Type'] = 'application/json'
    temp_header['Accept'] = 'application/json'

    data = {
        "GroupCreationInfo": {
            "groupName": group_name
        }
    }

    res = requests.post(url + 'groups', headers=temp_header, data=json.dumps(data))

    if res.status_code == 200:
        print('{} Group Created...'.format(group_name))
    else:
        print(res.status_code)
        print(res.headers)
        print(res.text)
        exit(res.status_code)

我尝试使用json代替data,但仍然遇到同样的错误。使用REST API客户端,我能够成功拨打电话。其余客户端如下所示: enter image description here 如果有人能指出一些知识,并指出我正确的方向,我会非常感激。小心。

2 个答案:

答案 0 :(得分:0)

您应该指定headers=temp_header而不是headers=headerMISSING_REQUIRED_PARAM经常关注内容类型标题,正如您所看到的,IS包含在屏幕截图测试中。

答案 1 :(得分:0)

所以我想通了,我想我将错误的有效负载传递给数据参数。我将代码更改为:

data = {
        "groupName": group_name
    }

看起来我不需要"GroupCreationInfo"参数。