Using requests with an Authorization header?
dieter at handshake.de
Wed Jul 29 08:01:54 CEST 2015
devnzyme1 at use.startmail.com writes:
> Has anyone ever used an authorization header with the requests library? I tried using:
>>>> from requests.auth import HTTPBasicAuth
>>>> requests.get('https://api.github.com/user', 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):
requests.post(url, data=data, params=params,
auth=(user, passwd), timeout=timeout,
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