problems with module Cookie

John J. Lee jjl at pobox.com
Sun May 30 20:56:10 EDT 2004


Manlio Perillo <NOmanlio_perilloSPAM at libero.it> writes:
[...]
> >> Standard Cookie module (with my corrections) plus httplib module is
> >> really all I need.
> >
> >Cool.
> >
> 
> Yes, there exists programs that are simple (as there exist programming
> languages that are simple)!
> 
> Actually what I do is to download several files from a server.
> Some files/pages are generated by a script (so I have to post an
> x-www-form-urlencoded string).
> 
> I don't want to use urllib2 because it (as I think) for every request
> connects to the server, do the request and disconnect.

Yes, that's true.  I should fix it...


> I need cookies because the server (as many other) authenticate user
> with cookies.
> So the simple algorithm is:
> 
> -connect to the server
> -read a cookie from a file
> -send the cookie to the server
> -if the server send a cookie, the old one must be updated: with
> standard Cookie this is simple: cookie.update(newcookie)
> - ...
> - save the cookie to a file
> 
> 
> This is very simple to do with httplib and Cookie modules, so why to
> use more involved modules?

No reason at all if you're happy with it, of course.  That was what my
"Cool" was meant to communicate.

*Using* urllib2 is less involved even than your little algorithm
above, of course (neglecting bugs, of course, including the persistent
connection bug, which -- though it could certainly be a problem -- I
confess has never actually troubled me, despite having used it to
repeatedly fetch tens of millions of records in the past).

Why use modules whose *implementation* is more involved?  Because
they're even easier to use, and because, even for simple scripts like
your's, not every case is as simple as the one you happen to have met.
I know from experience that it can quickly get *very* tiresome to do
some of this stuff by hand (even if only a few things like
redirections and cookies are involved).  And personally, I don't even
like to *think* about it, or to have to maintain it in future if I can
avoid it, regardless of how simple (ignoring for the moment that I
have to maintain the library itself ;-).

As for why the complications... well, if you want to know, read the
code (no, don't :-).


John



More information about the Python-list mailing list