[twill] Loading cookies (was Re: cookie client)
John J Lee
jjl at pobox.com
Thu Aug 3 17:33:08 PDT 2006
On Thu, 3 Aug 2006, John J Lee wrote:
[...]
> 2. Tell twill where to find your "cookie jar" with the "load_cookies"
> command.
[...]
If you don't have the original password, this is what you have to do, of
course.
Unfortunately, it looks like twill doesn't support loading Firefox or
Internet Explorer cookies yet (it can load and save cookies, but only in a
special format not used by browsers). ClientCookie and mechanize can load
Firefox and IE cookies, however. I'll try and point you in the right
direction, but first: Are you on Windows? Which browser are you using?
Titus -- why not have twill's load_cookies load the IE cookies if you're
running on Windows and there's no cookie jar argument (by instantiating an
MSIECookieJar and using .load_from_registry())? That's the preferred way
to load IE cookies (always assuming that MSIECookieJar still works -- it
parses an undocumented MS file format...). If there's an argument, I
think twill should attempt to .load() using each class in turn --
LoadError tells you it's the wrong format for that class (MSIECookieJar,
MozillaCookieJar, LWPCookieJar -- order shouldn't matter). If you add
support for Firefox cookie saving, you should also add the warnings about
this from the mechanize docs (IIRC, that a running Firefox may clobber
your changes, and you should back up any cookie files that contain
important cookies). I think save_cookies without an argument should use
the filename and file format that were used on the previous load_cookies.
Finally, note MSIECookieJar does not support saving, and iteration won't
cause loading of cookies unless .delayload is true. The delayload thing
can be significant for MSIECookieJar because each cookie is in its own
little file (or something similar, I forget), so I suggest having
delayload=False until somebody asks for show_cookies, at which point you
should call .load_all_cookies() before iterating.
John
More information about the twill
mailing list