
Auth token worked in Postman. Python said 401.
Auth token worked in Postman. Python said 401. Tested an API endpoint in Postman. Token worked perfectly. Copied the exact same token to Python script and got instant 401 Unauthorized. Spent way too long thinking the API was rejecting my script. Building a scraper for a client portal that needed Bearer token auth. Got the token from their developer console, threw it into Postman: GET / api / v1 / orders Authorization : Bearer eyJhbGc ... Response: 200 OK. Perfect. Copied token to Python: import requests token = " eyJhbGc... " headers = { " Authorization " : f " Bearer { token } " } response = requests . get ( " https://api.example.com/orders " , headers = headers ) print ( response . status_code ) # 401 Why. Tried Everything Thought maybe requests library had weird header handling. Tried adding User-Agent, Content-Type, bunch of random headers people suggested on StackOverflow. Still 401. Checked token expiration. Valid for 24 hours. Generated new one just in case. Same result. Logged
Continue reading on Dev.to Python
Opens in a new tab


