[BangPypers] automate logging (Pythonic)

Anand Balachandran Pillai abpillai at gmail.com
Thu Jul 24 13:46:09 CEST 2008


Don't bother with password managers. For HTTP basic authentication,
the quickest way is to add the auth header yourself. Here is the code.

>>> import urllib2, base64
>>> r = urllib2.Request('http://www.tek-tips.com')
>>> auth=base64.encodestring('%s:%s' % ('johnny','yesyes')
... )
>>> auth
'am9obm55Onllc3llcw==\n'
>>> r.add_header('Authorization','Basic %s' % auth)
>>> urllib2.urlopen(r)
<addinfourl at 2145898156 whose fp = <socket._fileobject object at 0x7ff35304>>


--Anand

On Thu, Jul 24, 2008 at 5:05 PM, Vijay Ramachandran <vijay750 at gmail.com> wrote:
> On 7/24/08, bangpypers-request at python.org <bangpypers-request at python.org>
> wrote:
>>
>> From: Pythonic <pythonic at gmail.com>
>> Subject: Re: [BangPypers] automate logging
>> To: leo_365 at yahoo.com,  Bangalore Python Users Group - India
>> leo davis wrote:
>> >
>> > Hello,
>> > I'm trying to write a code to automate logging into a website.I have
>> > chosen the forum 'www.tek-tips.com' as an example and tried this
>> > script on it....But it doesnt seem to work...What am i missing
>> > here..plz help
>> >
>> > theurl = 'www.tek-tips.com'
>> > protocol = 'http://'
>> > username = 'johnny'
>> > password = 'yesyes'
>> >
>> > passman.add_password(None, theurl, username, password)
>
> change "theurl" to contain the protocol as well, i.e., instead of the above,
> try
> passman.add_password(None, protocol + thurl, username, password)
>
> If it works - don't ask me why! I ran into the same problem, and discovered
> this through trial and error.
>
> Vijay
>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
>



-- 
-Anand


More information about the BangPypers mailing list