how to browse using urllib2 and cookeilib the correct way

John J. Lee jjl at pobox.com
Wed Apr 26 16:56:18 EDT 2006


jnair at ensim.com writes:
[...]
> 1) >>>import urllib2,urllib,cookielib
> 2) >>>cj = cookielib.CookieJar()
> 3) >>>opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cj))
> 4) >>>data = urllib.urlencode	( { "username" : "user" ,
> 	 "password" :"****" } )
> 5) >>>fp = opener.open(
> "https://rhn.redhat.com/rhn/LoginSubmit.do",data )
> 6) >>>fp.url

.url is not a public interface.  Use .geturl() .


> 'https://rhn.redhat.com/rhn/ReLogin.do?url_bounce=/network/index.pxt'
> 7) >>>fp = opener.open(
> "https://rhn.redhat.com/rhn/LoginSubmit.do",data )
> 8) >>>fp.url
>    'https://rhn.redhat.com/network/index.pxt'

Dunno.  Perhaps because a Refresh is used to handle the login?  twill
is based on mechanize, which handles Refresh headers.


John




More information about the Python-list mailing list