ClientCookie bug (followup)

Mark Carter cartermark46 at ukmail.com
Wed Aug 27 05:00:27 EDT 2003


>     opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(c))
> 
>     url = 'http://businessplus.hemscott.net/corp/crp03733.htm'
>     response = opener.open(url)

Huzzah, we have liftoff!

> All of this is explained in the web page, though. 

You are right! All the technical information is there. But can I
suggest a
change in the docs that might spell it out a bit more obviously to
someone
coming to the module from fresh? Something like:

h1: Examples

h2: Simple example

 import ClientCookie
 response = ClientCookie.urlopen("http://foo.bar.com/")

This function behaves identically to urllib2.urlopen, except that it
deals with cookies automatically. That's probably all you need to
know.

h2: Using Internet Explorer or Netscape/Mozilla cookies

    c = ClientCookie.MSIECookieJar(delayload=1) # see note 1
    c.load_from_registry(username='joe bloggs') # see note 2
    opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(c))

    url = 'http://foo.bar.com/'
    response = opener.open(url)

    print response.info()  # headers
    print response.read()  # body

h3: Notes
1. Mozilla users should use MozillaCookieJar() instead of
MSIECookieJar
2. Usually only win98 and 95 users need supply the username. As an
alternative
to loading from the registry, consider using the line
    c.load_cookie_data('cookie-file.txt')
instead.


I think that the above is much more up-front, and is likely to satisfy
the
majority of users, who will probably just want basic cookie handling,
without
pouring over the documentation. Ideally, it should be at the top,
where people
will see it first, and before those more complicated examples.


Hope this is useful!




More information about the Python-list mailing list