0
votes

I've been trying to post a payload to an endpoint, the endpoint requires bearer token. using the python requests, I'm trying to post the bearer token in the header as

from requests import Session

http= Session()

accessToken = getToken(url=uri,data=payload)

authorization_header_string = 'bearer ' + accessToken

requestHeaders = {"Content-type": "text/plain", "Authorization":authorization_header_string}
         

headerData={"content-type":"text/plain","authorization":requestHeaders}

resp= http.post(url=uri,data=payload,headers=headerData)

but all I get is 401 error, while if I use the same token in postman it works fine. I'm using requestbin to check wherein the authorization shows up only sometimes in the header.

1
Can you show the actual code (naturally without the actual token or URI), just so we can be sure about the format of your Authorization header? - AKX
Try using: "Bearer " + accessToken; only field names are case insensitive for HTTP headers; values may or may not be case sensitive. - Ionut Ticus
Updated the code now - rbc
Tried with "Bearer " + accessToken it still didn't work - rbc

1 Answers

0
votes

Try the following:

token = "your token"

headerData={"content-type": "text/plain", "authorization": "Bearer " + token}