dkoug Blog

Python3 requests with authentication

Python -- Posted on Oct. 17, 2018

Python3 requests with authentication

1
2
3
4
5
6
def get_data(auth_user, auth_passwd, url):
    headers = {'Accept': 'application/json'}
    response = requests.get(
        url, auth=requests.auth.HTTPBasicAuth(
            auth_user, auth_passwd), headers=headers)
    return json.loads(response.text)