简体   繁体   English

Python request.post缺少必需的参数

[英]Python request.post Missing Required Param

I've been looking around and trying to get a post request to work, but I haven't found any luck. 我一直在四处寻找工作,并希望获得职位要求,但是我没有发现任何运气。 I keep getting a MISSING_REQUIRED_PARAM each time the request is being made. 每次发出请求时,我都会不断收到MISSING_REQUIRED_PARAM My following code is shown below. 我的以下代码如下所示。

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)

I've tried using json instead of data , but still getting the same error. 我尝试使用json代替data ,但是仍然遇到相同的错误。 Using a the REST API client I was able to successfully make the call. 使用REST API客户端,我能够成功进行调用。 The rest client is shown below: 其余客户端如下所示: 在此处输入图片说明 If anyone can point shine some knowledge and point me in the right direction I would greatly appreciate it. 如果有人可以指出一些知识并指出正确的方向,我将不胜感激。 Take care. 照顾自己。

You should assign headers=temp_header not headers=header . 您应该分配headers=temp_header而不是headers=header MISSING_REQUIRED_PARAM is often griping about the content type header, which, as you can see IS being included in your screenshot test. MISSING_REQUIRED_PARAM通常MISSING_REQUIRED_PARAM是内容类型标头,正如您所见,它已包含在屏幕快照测试中。

So I figured it out, I guess I was passing the wrong payload into the data param. 所以我想通了,我想我是将错误的有效负载传递给了数据参数。 I changed the code to: 我将代码更改为:

data = {
        "groupName": group_name
    }

It looks like I didn't need the "GroupCreationInfo" parameter. 看起来我不需要"GroupCreationInfo"参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM