[Tutor] urllib2 and php authentication

Daniele d.conca at gmail.com
Sun Jul 27 02:31:10 CEST 2008


Hi,
I'm trying to connect to a site that requires a php login. I used the
urllib2 module in the following way:

>>> import urllib2
>>> user='xxx'
>>> password='yyy'
>>> hp = urllib2.HTTPPasswordMgr()
>>> uri = 'http://s2.ikariam.it/index.php?action=loginAvatar&function=login'
>>> hp.add_password(None, uri, user, password)
>>> opener = urllib2.build_opener(urllib2.HTTPBasicAuthHandler( hp))
>>> req = urllib2.Request(uri)
>>> opener.open(req).readlines()

Needless to say, it doesn't work. I get an html page back from the
opener saying username and/or password are invalid.
Can anyone point me in the right direction?

thanks a lot,
Daniele


More information about the Tutor mailing list