Using requests with an Authorization header?

dieter dieter at
Wed Jul 29 08:01:54 CEST 2015

devnzyme1 at writes:

> Has anyone ever used an authorization header with the requests library?  I tried using:
>>>> from requests.auth import HTTPBasicAuth
>>>> requests.get('', auth=HTTPBasicAuth('user', 'pass')
> from their docs online but that's not working and I don't see anything about authorization headers

We are using it like this (successfully):, data=data, params=params,
              auth=(user, passwd), timeout=timeout,
              verify=verify, headers=jsonHeaders,

i.e. "user" and "password" are not wrapped into an "HTTPBasicAuth"
but directly passed as tuple. However, I expect that
it would also work with an "HTTPBasicAuth" wrapping.

Note that you must pass the real username and password, not
the literals "'user'" and "'pass'".

More information about the Python-list mailing list