isic5
isic5

Reputation: 191

How to pass OAuth2 access token for get request?

I cannot figure out how to pass my retrieved access token to the get requests without manual copy and paste. I tried already doing:

#get token

access_token = oauth.fetch_token(token_url='https://XXX.de/api/token', auth=auth)

hed = {'Authorization': 'Bearer {}'.format(access_token)}

But then I get error 401.

If I copy and paste the code manually into the below format, it works:

hed = {'Authorization': 'Bearer ed361d11111111351e43c685bbda7229407b290d'}

This is how I get it from oauth.fetch_token(token_url='https://XXX.de/api/token', auth=auth):

{'access_token': 'ea00be2538ebccc051c66f392ee313797549de04', 'expires_in': 3600, 'token_type': 'Bearer', 'scope': None, 'expires_at': 1559749057.8817663}

What am I doing wrong? Still fairly new to requests..

Upvotes: 0

Views: 154

Answers (1)

Aero Blue
Aero Blue

Reputation: 526

It's a dictionary:

access_token = {'access_token': 'ea00be2538ebccc051c66f392ee313797549de04'}

Vs:

access_token["access_token"] = 'ea00be2538ebccc051c66f392ee313797549de04'

Upvotes: 2

Related Questions