Greg Jorgensen gregj at
Fri Mar 16 06:35:56 CET 2001

A cookie is just a text file stored in a special place where the browser can
find it. Where exactly the cookies go depends on your OS and browser.

Using a text file to store the key would seem the easiest solution, but
client-side Javascript can't create or write a file.

I think you should generate unique IDs on the server, not on the client.
Here's one way to handle it:

1. Client browser sends form data to server.
2. Server processes form, generates a unique ID, stores the form data keyed
by the unique ID.
3. Server replies with a "thank you" or "database updated" page that also
writes a cookie.
4. Python program starts up and looks for the cookie. Depending on your OS
and browser the location and name of the cookie will vary, but with a little
experimenting you can easily find the most likely locations.
5. Python program reads the cookie. Open your cookie with a text editor to
see what's in there--it's just name: value pairs.
6. Python program sends HTTP request to server with unique ID it got from
the cookie.

Obviously this won't work if the client has disabled cookies. With a little
more trouble you can detect this and perhaps put the unique ID on the
response page and tell the user to save it or something. Or embed the unique
ID in the reply page and tell the user to save that page and give it a
specific name, then have your Python program open that text file and find
the unique ID in there.

Depending on your requirements and security concerns, you can either have
your database program generate the unique ID (my preference), use the
Windows GUID functions (which are available to ASP on the server), or
implement one of the GUID functions you can easily find on the web. Many
programmers have solved this in one way or another; send email to me if you
want specific advice on generating unique IDs from your database engine.

Good luck.

"Ken Seehof" <kens at> wrote in message
news:mailman.984707839.22839.python-list at
Short version:

Is it possible for a stand-alone python application to read a cookie without
the help of a browser?"

Long version:

I have a web page W and a client side python script P.  I want W to generate
a GUID (perhaps using javascript) which is then sent to a server S, where it
is to be used as a key in a database.  Now I run P (on the client, and not
in a browser) and I want P to somehow find the value of the GUID, so that it
can query the database on S.

Alternate question:

Is there a technique common to both javascript and python that will obtain a
unique identifier for a computer (e.g. IP address).  It must not be browser


I need to write a record of data from an html form, keyed by some kind of
unique client id, to the server and then be able to query that record from a
stand alone python script running on the client.  The missing link is
getting the html form and the python script to agree on a value for the id;
the rest is easy.

Greg Jorgensen
Portland, Oregon, USA
gregj at

More information about the Python-list mailing list