I have a request URI and a bearer token for POST request.
headers = {'content-type': 'application/json', **'Authorization': 'Bearer hfgeyJr='**}
If I use:
response = requests.post(url=url, data=json_request, headers=headers, verify=False)
I am getting the response as below:
{ "title" : "Bad Request", "status" : 400, "detail" : "JSON parse error: Unrecognized token 'value': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'value': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream);]"
When I tried with below header format,
headers = {'content-type': 'application/json', **'Authorization': 'Bearer token:hfgeyJr='**}
I am getting <Response [401]>
When I tried via postman, I am getting successful response with the above data
I really appreciate if someone can explain how to pass bearer token with other headers successfully.
python version: 3.12.3
requests library: 2.31.0
Thanks in advance!
Divya Retarus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.