简体   繁体   中英

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. 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. Using a the REST API client I was able to successfully make the call. 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 . MISSING_REQUIRED_PARAM is often griping about the content type header, which, as you can see IS being included in your screenshot test.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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