Cookie based authentication

chandan mathur cmathur at cis.poly.edu
Mon Jun 17 14:34:08 EDT 2002


I am still stuck on how to use client cookie
(http://wwwsearch.sourceforge.net/ClientCookie/). I am trying to write a
script that automatically logs in to http://www.fool.com/login.asp (SSL
encryption) and downloads pages that i need. This is what i have tried so
far: I logged in using internet explorer and opened the cookie file from
windows explorer. Using set_cookie method in Cookies, i tried to set the
cookie as best as i could.. (i probably did something wrong here).

import ClientCookie
import urllib2
import urllib
request = urllib2.Request("http://www.fool.com/Login.asp")
result = urllib2.urlopen(request)
c = ClientCookie.Cookies()
c.extract_cookies(result, request)


# let's say this next request requires a cookie that was set in result
request2 = urllib2.Request("http://my.fool.com/index.htm")
c.add_cookie_header(request2)
c.set_cookie(None,"Wookie=Ref=","FoolV=5&Uid=123146592&LastVisit=6%2F17%2F20
02+1%3A24%3A20+PM&FirstVisit=6%2F17%2F2002+12%3A27%3A22+PM&Username=westlab"
,"/","fool.com/",None,None,None,None,None,None)
result2 = urllib2.urlopen(request2)
print result2.geturl()
print result2.info()  # headers
print result2.read()

it gets the wrong page


Thanx for your time

Chandan






More information about the Python-list mailing list