urllib2: correct way how to add a header to the *initial* request?

M

Matěj Cepl

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

this is probably a dumb question but I just cannot find a way
how to create AuthHandler which would add Authorization header
to the FIRST request. The only thing I see in urllib2.py are
various http_error handler which add Authorization header to the
ADDITIONAL request which handles the error.

However, when looking at http://www.ietf.org/rfc/rfc2617.txt,
section 2, I see this:

A client MAY preemptively send the corresponding
Authorization header with requests for resources in that
space without receipt of another challenge from the server.

And really many servers (e.g., api.github.com) expect the
Authorization header to be sent with the initial request, and
actually they broken
(http://developer.github.com/v3/auth/#basic-authentication) so
instead of 401 they send 404 status code.

Anybody has any idea how to subclass *AuthHandler so that it
would add the header on the initial request?

Best,

Matěj

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iD8DBQFS9kui4J/vJdlkhKwRAqH1AJ9884WT6pjdu/U54khpHUUVWRcFkgCdEQn9
TNtb2lcc4Nrf1zmftn5u8Zg=
=4R/2
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top