I’ve installed gae-sessions to my development environment but it doesn’t seem to be storing anything. Here’s a basic example:
session = get_current_session()
session.get('some_num', 3)
Then later on in some other function…
session = get_current_session()
session['some_num'] = 4
And here’s the error I get in the console:
KeyError: 'some_num'
Not a very helpful error. I’m pretty sure i’ve followed the instructions to the letter but maybe there’s something i’m missing?
edit
appengine_config.py
from gaesessions import SessionMiddleware
import os
def webapp_add_wsgi_middleware(app):
app = SessionMiddleware(app, os.urandom(32))
return app
Offending code
class Test(webapp.RequestHandler):
def get(self):
session = get_current_session()
if session.is_active():
# set session['some_num'] to whatever was in there or three, otherwise
session['some_num'] = session.get('some_num', 3)
# later, session['some_num'] should exist and be equal to 3 ...
assert session['some_num'] == 3
# ... and is actually 'settable'
session['some_num'] = 4
else:
self.response.out.write("Session is NOT active")
.is_active() doesn’t return true.
In your code (as it stands) you don’t add
some_numto your session dictionary in the first place. Try: