[mod_python] Cookies & Redirects

Daniel West dwmp at opti.cgi.net
Sun Aug 22 04:14:33 EDT 2004

I have a script that needs to receive a request, set a cookie, and then 
redirect to another location.  I'm using PSP on mod_python 3.1.3.  I'm not 
getting the Set-Cookie header in the request response.  Here's the code I'm 

cookie = "..." # set the cookie to something
req.headers_out.add('Set-Cookie', cookie)
req.headers_out["Location"] = "http://..."
raise apache.SERVER_RETURN, apache.HTTP_SEE_OTHER

I can pull that request up in telnet and the Set-Cookie header is not 
there.  But if I comment out the last line (raise apache.SERVER_RETURN, 
apache.HTTP_SEE_OTHER) then the Set-Cookie header appears in the 
headers.  Also, if I change the line to "raise apache.SERVER_RETURN, 
apache.OK" then the Set-Cookie header appears in the response headers as 
well.  I've also tried returning apache.HTTP_MOVED_TEMPORARILY but no luck 
there either.  Why is it that mod_python seems to honor the Set-Cookie 
header for the OK status code, but not the others?



More information about the Mod_python mailing list