[mod_python] About retrieving cookies...

Martijn Moeling martijn at xs4us.nu
Thu Mar 4 11:39:36 EST 2010


Hi Victor,

Cookies are send to the browser in the HTTP header, so yes set them before any write operation as the headers are send at the first write.

Next, Why are you trying to get the contents from a cookie which is stored on the "client" via a call to the server, it is not logical, 
I suggest you read about cookies and how they work. I can give you a very long description about how cookies work but this is not mod_python related.

If you really want to do this (I do not see any reason though). Google on "access cookies from javascript" or do a search on "document.cookie". Like Firefox (I think FF uses javascript for this too).
you CAN access it locally. Use Firebug (javascript debug plugin) to investigate stuff.

I hope this helps

Martijn



On Mar 4, 2010, at 4:49 PM, Víctor wrote:

> Dear all,
> 
> I've got a bunch of problems using cookies. First, it seems that if
> you want to store a cookie, you MUST do it before any req.write()
> sentence, isn't it?
> 
> Next... I've managed to store a simple cookie named "login_cookie"
> with value 100. I can see it in the cookies manager in firefox, and it
> has the right value. The cookie has an expiration time of 30 days from
> now.
> 
> The problem is that... it's absolutely impossible to retrieve it from
> the browser.
> 
> I have a small test page with this javascript function (it uses prototype):
> 
> function accessPage(){
> 				new Ajax.Request(access_base_dir+'access', {
> 			
> 					method: 'post',
> 					
> 					onSuccess: function(response) {
> 						$("resultados").innerHTML =response.responseText;
> 					},
> 					
> 					onFailure:function(response) {
> 						$("resultados").innerHTML= "Failed to access."+response.responseText;
> 
> 					}
> 				});
> 				
> 			}
> 
> This function just asks 'access' to return the content. 'access' looks
> like this:
> 
> @_session_getter
> def access(req):
> 	
> 	(logged,user_id) = getSessionData(req)
> 	
> 	all_cookies = Cookie.get_cookies(req)
> 	
> 	req.write("Access: " +str(all_cookies))
> 
> And guess what, it only writes Access: {'pysid': } , the session
> cookie, but "login_cookie" is not anywhere.
> 
> My apache config for this folder is:
> 
> 
> <Directory "htdocs/python/test">
> 	AddHandler mod_python .py
> 	PythonHandler mod_python.publisher
> 	PythonDebug On
> </Directory>
> 
> Do you know If I'm missing anything obvious that prevents the cookie
> retrieval to work?
> 
> Thanks!,
> -- 
> 
> Víctor Gil Sepúlveda
> E. Informatica - FIB - UPC
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python




More information about the Mod_python mailing list