I am trying access a REST API.
I can get it working in Curl/REST Client (the UI tool), with preemptive authentication enabled.
But, using urllib2, it doesn’t seem to support this by default and I can’t find a way to turn it on.
Thanks 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a simple Preemptive HTTP basic auth handler, based on the code from
urllib2.HTTPBasicAuthHandler. It can be used in the exact same manner, except anAuthorizationheader will be added to every request with a matching URL. Note that this handler should be used with aHTTPPasswordMgrWithDefaultRealm. That’s because there is no realm coming back in aWWW-Authenticatechallenge since you’re being preemptive.