Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python requests, keep getting 401 error when accessing an API

I am trying to make a connection to this API with requests. Specifically I was trying to access the "all applications" endpoint, yet I am having trouble making an initial connection.

>>> import requests
>>> 
>>> url = "https://manager.gimbal.com/api/applications"
>>> headers = {
... 'Authorization': 'Token <MyApiKeyIsHere>',
... 'content-type': 'application/json'
... }
>>> 
>>> 
>>> 
>>> r = requests.get(url, headers=headers)
>>> r
<Response [401]>

I am a bit confused as to why I am not getting an unauthorized connection to the API. If anyone can offer some pointers, that would be extremely helpful.

like image 780
ApathyBear Avatar asked Dec 21 '25 12:12

ApathyBear


1 Answers

The documentation seems to point out that the value is actually token=TOKEN, not just the token itself...

AUTHORIZATION: Token token=my_organization_server_api_key

Try replacing

'Authorization': 'Token <MyApiKeyIsHere>',

with this, and see if it responds properly

'Authorization': 'Token token=<MyApiKeyIsHere>',
like image 79
Bryan Avatar answered Dec 23 '25 00:12

Bryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!