Python requests library returns 401 Unauthorized when calling my API

asked 3 days ago8 viewsen

0

The API works successfully in Postman, but the same request from Python returns 401 Unauthorized. I am passing the bearer token in the request headers.

import requests

url = "https://api.example.com/customers"

headers = { "Authorization": "Bearer my-token", "Content-Type": "application/json" }

response = requests.get(url, headers=headers)

print(response.status_code) print(response.text)

=================================================================== Error 401 Unauthorized

Environment:Python 3.12Windows 11

🤖 AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

No Answers

Sign in and verify your email to post an answer.