Web authentication urllib2

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jan 24 11:05:16 CET 2009

En Sat, 24 Jan 2009 06:52:57 -0200, Gabriel <dunmer at dreams.sk> escribió:

> I'm new in Python and i would like to write script which need to login  
> to a website. I'm experimenting with urllib2,
> especially with something like this:
>      opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
>      urllib2.install_opener(opener)
>      params = urllib.urlencode(dict(username='user', password='pass'))
>      f = opener.open('https://web.com', params)
>      data = f.read()
>      f.close()
> And the problem is, that this code logs me in on some sites, but on  
> others doesn't, especially on the one I really
> need to login. And i don't know why. So is there some way how to debug  
> this code and find out why that script cannot
> login on that specific site?

Start by looking at the web page that you normally use to log into the  
site; probably the form contains more fields than just username and  
In some cases it may be necesary to use ethereal (or any protocol  
analizer), to see exactly what is actually transmitted when you log in  
using your browser. Later you may try to reproduce the same thing with  

Gabriel Genellina

More information about the Python-list mailing list