Search code examples
pythonhttp-authenticationhttplib2

Can I do preemptive authentication with httplib2?


I need to perform preemptive basic authentication against an HTTP server, i.e., authenticate right away without waiting on a 401 response. Can this be done with httplib2?

Edit:

I solved it by adding an Authorization header to the request, as suggested in the accepted answer:

 headers["Authorization"] = "Basic {0}".format(
        base64.b64encode("{0}:{1}".format(username, password)))

Solution

  • Add an appropriately formed 'Authorization' header to your initial request.