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

Discussion in 'Python' started by Matěj Cepl, Feb 8, 2014.

  1. 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)

    iD8DBQFS9mlu4J/vJdlkhKwRAvJXAJoDnUWRm2E/7UbLQ867jRwzcmeHngCfd2YF
    iivTwaqTgYPZTnAQBk7krGg=
    =WdUK
    -----END PGP SIGNATURE-----
     
    Matěj Cepl, Feb 8, 2014
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ayende Rahien

    Correct way to add formatted HTML?

    Ayende Rahien, Dec 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    586
    Steve C. Orr [MVP, MCSD]
    Dec 18, 2003
  2. Josef Cihal
    Replies:
    0
    Views:
    1,252
    Josef Cihal
    Sep 5, 2005
  3. Replies:
    3
    Views:
    459
    John J. Lee
    Apr 26, 2006
  4. Replies:
    1
    Views:
    321
    John J. Lee
    Apr 26, 2006
  5. mlt
    Replies:
    2
    Views:
    1,119
    Jean-Marc Bourguet
    Jan 31, 2009
  6. nRk
    Replies:
    1
    Views:
    1,169
    Steven D'Aprano
    Feb 12, 2009
  7. Matěj Cepl
    Replies:
    0
    Views:
    150
    Matěj Cepl
    Feb 8, 2014
  8. Grant Edwards
    Replies:
    32
    Views:
    348
    Grant Edwards
    May 9, 2014
Loading...