httplib with NETRC authentication

Akira Li 4kir4.1i at gmail.com
Wed May 14 11:44:00 EDT 2014


Chris Angelico <rosuav at gmail.com> writes:

> On Wed, May 14, 2014 at 9:33 AM, pratibha natani <en.pratibha at gmail.com> wrote:
>> I am trying to establish http connection to a gerrit host using
>> netrc authentication. I have a netrc file created with following
>> entries:
>> machine host1.com login name password pass
>>
>> I did a debug and saw that my netrc file is being read
>> correctly. Also in the connection object(after sending request) a
>> header got created with appropriate credentials:
>>  'headers': {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ='}
>>
>> Still I get 401,Unauthorized in response. Any help would be greatly appreciated!
>
> The obvious question is: What *does* work? Does it work when you use
> wget, or some other application? Then go and look at what that sends
> for its authentication headers. Tip: It won't be "Authorization".

"Authorization" is the appropriate header for basic http authentication:
http://tools.ietf.org/html/rfc2617#section-2

Here's a code example for urllib2:
https://gist.github.com/kennethreitz/973705#comment-56387


--
akira




More information about the Python-list mailing list