0

I'm trying to change, or update the authorization for a Python Requests Session. I tried two different ways:

sesh.headers.update({'Authorization': 'Bearer {}'.format(access_tok)})
req = sesh.get('https://website/{}'.format(oureq.get('pmid')), headers ={'Authorization': 'Bearer {}'.format(access_tok)} )
print("Doing guess at get for pmid status code is {}".format(req.status_code))
print("Headers sent {}".format(req.request.headers))

The response is below. NOTICE that the Authorization is not bearer! It is still Basic. What am I doing wrong?

Doing guess at get for pmid status code is 200
Headers sent {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Authorization': 'Basic cGblah4uY29tOktuaWdodDg4IQ==', 'Cookie': 'ARRAffinity=9c41ffc1313blahbluhc393a76feb8848401b3c822cbaeaae362e0316b; ARRAffinitySameSite=9c41ffc131blah6c2a5fbbd9c393a76feb8848401b3c822cbaeaae362e0316b; coid=1482; domain=<down>ia; firstUnitId=195878; locale=en-US; logourl=https://testurl.com/SUCOMR/logo_agency.gif; ophoster=owner; pmid=ff82; pmname=Sumtreats; source=EscVRS; timezone=MST; tld=com; url=https://<website>.com/dffd/; utcoffset=-07'}
Kurt Peters
  • 161
  • 1
  • 7

1 Answers1

0

Requests defaults to a "Basic" type authorization http request. You can read more about different requests types here:

https://iq.opengenus.org/user-authentication-techniques-types/

This problem was previously solved here: Making an API call in Python with an API that requires a bearer token

They created an Auth class and implementing it in requests:

import requests    
class Auth(requests.auth.AuthBase):
        ...
response = requests.get('https://website/{}'.format(oureq.get('pmid')), auth=Auth(access_tok))
Dharman
  • 30,962
  • 25
  • 85
  • 135
groseries
  • 38
  • 4