Login Authentication with cookies...

chandan chandan_mathur at hotmail.com
Mon Jun 3 23:05:25 EDT 2002


Problem: - write a python script to access pages that are password
protected, but DONT return a 401 forbidden code. i.e. Login to a
website like hotmail and check you mail message or in my particular
case, http://www.fool.com/login.asp
and then download the discussion board messages for a particular

Attempts so far: - The login and password protection is based on
cookies, so I used ClientCookie.py as follows (although, i am not sure
how to use it properly)

import ClientCookie
import urllib2
import urllib
params = urllib.urlencode({'login':'login','password':'password'})
request = urllib2.Request("http://www.fool.com/login.asp", params)
# note we're using the urlopen from ClientCookie, not urllib2
result = ClientCookie.urlopen(request)

Error message: 
Traceback (innermost last)
  File "c:\python22\programs\demos\trial", line 7, in ?
    result = ClientCookie.urlopen(request)
NameError: global name 'types' is not defined

Program disconnected.

I dunno what to do about the types in ClientCookie.py... even the
example code given in the README file for this library returns the
same error.., i am using windows XP, python 2.2

ClientCookie can be obtained from here -

Thanx for the help

P.S : Newbie...

More information about the Python-list mailing list