ClientCookie bug

Mark Carter cartermark46 at ukmail.com
Thu Aug 14 21:19:35 CEST 2003


jjl at pobox.com (John J. Lee) wrote in message news:<87fzk4sav2.fsf at pobox.com>...
> Syver Enstad <syver at inout.no> writes:
> 
> > cartermark46 at ukmail.com (Mark Carter) writes:
> > 
> > > I am using Windows 98, python 2.3, ClientCookie 0.4.3a.
> > > 
> > > When I do:
> > > import ClientCookie
> > > import os
> > > c = ClientCookie.MSIECookieJar(delayload=1)
> > > c.load_from_registry()
> > > 
> > > I get the response:
>  [...]
> > > KeyError: 'USERNAME'
> > > 
> > > Basically, it doesn't like USERNAME as an environment variable.
> > 
> > I suspect this only works on "real" win32 (the NT family) operating
> > systems, which define USERNAME, and not hybrid dos/win32 systems like
> > the win9x family.
> 
> Anybody know the best way to get the username without win32all
> installed?
> 
> Mark: I don't have a win9x box, but try replacing that
> os.environ['USERNAME'] with getpass.getuser().  You'll need to stick
> an import getpass in there too, of course.  Let me know if that works.
> 
> The rest of the code should work OK on win9x.
> 
> 
> John

My apologies - the bug exists in my own brain, not in the code. I had in mind
that a fix would be required in ClientCookie - but now I know better.

To get it to work, I simply called:
os.environ['USERNAME'] = 'mark carter'  # or whatever your name is
before calling 
c.load_from_registry() # c is a MSIECookieJar

It's an embarassingly simple solution to the problem - but it took me a while
to figure it out. Although there is nothing wrong with code, perhaps it would
help new users of the library to mention it. Maybe the solution is somewhat
obvious in retrospect - but it took me a while before the penny dropped.

Another approach - which I actually prefer - is to copy the cookie to the local
directory and load it using load_cookie_data(). At first, I was having no end
of problems with it - until I discovered that you should use the (binary)
cookie, not an ASCII cookie that you obtain from performing a cookie export
from MSIE.  ... and don't forget to call ClientCookie.MSIECookieJar() WITHOUT
the delayload argument.

So, sorry for the false alarm - but hope my investigations will prove useful to
others.




More information about the Python-list mailing list