[mod_python] question - Getting/Setting Cookies

Michael C. Neel neel at mediapulse.com
Thu Feb 12 12:40:47 EST 2004

> Seems that Debian's 'latest' version of mod_python, vers 2.7.10, is
> downright ancient.

No, 2.7.10 is the latesst for Apache 1.3, 3.x is for Apache 2 - however
no new features or corrections outside of security fixes are being done
to 2.x mod_python, so it doesn't have many of the things that 3.x does.
If you can switch to Apache 2 that might be best, but going from 1.3 to
2 isn't always easy depending on what modules/apps are using 1.3.

That said, if you are staying with 2.7.10, I use this to read cookies:

    # Get any cookies we may have
    cstr = ""
    if req.headers_in.has_key("Cookie"):
        for cookie in req.headers_in["Cookie"]:
            cstr += cookie

    cookies = Cookie.SimpleCookie(cstr)

And this to write a cookie:

            CNew = Cookie.SimpleCookie()
            CNew["test"] = "test"

( you want to use .add so as to not overwrite any other set-cookie
headers, as there can be more than one).


More information about the Mod_python mailing list