[Tutor] urllib2 and php authentication

W W srilyk at gmail.com
Sun Jul 27 03:58:34 CEST 2008


On Sat, Jul 26, 2008 at 7:31 PM, Daniele <d.conca at gmail.com> wrote:

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

It requires a php login, or php handles the login?

>>> 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?
>

If php is handling the login, my guess is that it's receiving the info via
either POST or GET.

And if you don't have access to the script, and you're not sure what the
names of the values are, that might require some trial and error.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080726/f5e7efc5/attachment.htm>


More information about the Tutor mailing list