简体   繁体   中英

Python: Getting “internalServerError:500” while trying to use requests.post

Getting the "internalServerError" while using the requests.post method, and the same data, header, URL is working through Postman.

In the headers, I'm using Authorization, Content-Type.and the data is in JSON.

r = requests.post (url,headers=headers,data=data)

> <Response [500]> {"message":"error.internalServerError","description":"Internal server error","fieldErrors":null}

If you pass a dictionary to the data parameter the data will automatically be form-encoded when the request is made.

However, according to the docs :

There are times that you may want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly .

and:

Instead of encoding the dict yourself, you can also pass it directly using the json parameter (added in version 2.4.2) and it will be encoded automatically

So you could also write:

r = requests.post(url, json=data)

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