I'm having a problem sending an authorization token with Bearer to NEST API via python requests:
curl https://developer-api.nest.com -H "Authorization: Bearer c.123"
-H "Content-Type: application/json"
works fine, however:
nest_url = "https://developer-api.nest.com"
headers = {'Authorization': str('Bearer ' + token), 'Content-type': 'application/json'}
print(headers)
nest_data_req = requests.get(nest_url, headers=headers)
which prints as:
{'Content-type': 'application/json', 'Authorization': 'Bearer c.123'}
fails with a 401 unauthorized, as far as I can tell they are trying to make the same request so why does curl work (and postman for that matter) and python requests fail?
The following image shows the same working in postman:
So this code works 1 in 10 times (the other 9+ give me 401 unauthorized):
url = "https://developer-api.nest.com/"
auth_t = token.encode("ascii", "ignore")
headers = {
'authorization': "Bearer " + auth_t,
'content-type': "application/json",
'cache-control': "no-cache",
}
response = requests.request("GET", url, headers=headers)
print(response.text)
if I press submit in postman it works everytime without fail.