WSGI : Cookies can only be called after the ** start_response **? -


i can not call cookie right after the:

 def application(environ, start_response): 

like this:

import cookie co = cookie.simplecookie()  def application(environ, start_response): co.load(environ['http_cookie'])  start_response('200 ok', ('content-type', 'text/html')) 

because although works.. cookie must set work.

if cookie not exist.. script fail.

the solution seems be..

placing under "start_response()"

if 'http_cookie' in environ:     co.load(environ['http_cookie'])  = co.get('a') , co['a'].value 

in other words:

import cookie co = cookie.simplecookie()  def application(environ, start_response):      start_response('200 ok', ('content-type', 'text/html'))      if 'http_cookie' in environ:         co.load(environ['http_cookie'])      = co.get('a') , co['a'].value      yield str(a) 

but method rather not strange given asking

 environ 

and yet has under

start_response() 

in order cookie.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -