I am having problems storing session variables in the webapp2 session store when working in GAE. I created a super simple application to reproduce the problem:
class MainHandler(webapp2.RequestHandler): def post(self): session = self.session_store.get_session() previous_value = session.get("myvalue") self.response.write(previous_value) def get(self): session = self.session_store.get_session() previous_value = session.get("myvalue") self.response.write(previous_value) session["myvalue"] = "Hi! " + (previous_value if previous_value else "")
The premise is that the get request sets the session variable, and post just records the response object.
I understand that after the get request is complete, the session is saved myvalue . After that, if I execute the post request, then the get request again, myvalue should still be there, although I did not set it again in the post handler. Alas, this is not so:
>>> cookies = None >>> for i in range(10): ... r = requests.get("http://localhost:11282/", cookies=cookies) ... cookies = r.cookies ... print r.text ... None Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! >>> >>> cookies = None >>> for i in range(10): ... r = requests.get("http://localhost:11282/", cookies=cookies) ... cookies = r.cookies ... print r.text ... r = requests.post("http://localhost:11282/", cookies=cookies) ... cookies = r.cookies ... print r.text ... None Hi! None Hi! None Hi! None Hi! None Hi! None Hi! None Hi! None Hi! None Hi! None Hi!
source share