pythonpython-requestsget

Python API GET Request "authorization failure" question


I tried testing API request using python and I am new at this, I am able to authorize properly and get the bearer token however for the GET request it seems that it is failing.

import requests
import json

MainURL = "api.mysite.com/"
DataForm = {'scope': 'api-tenant',
            'grant_type': 'client_credentials',
            'client_id': 'client id',
            'client_secret': 'client secret'
            }

AuthData = requests.post(MainURL + "oauth/token", data=DataForm)
print(AuthData.text)
AuthCont = json.loads(AuthData.text)

autHeader = {'Authorization': 'Bearer' + AuthCont["access_token"], 'Accept': 'application/json'}

GetApp = requests.get(MainURL + "api/v3/applications", headers=autHeader, verify=False)

print(GetApp.text)

Need help.


Solution

  • Answer from @Denis Yakovlev:

    With 'Bearer' + AuthCont["access_token"], you have to add a space like 'Bearer '. That's because a full form of the header is "Authorization: Bearer TOKEN", and not "Authorization: BearerTOKEN"