I used gaesessions on Google App Engine with Python to handle user login sessions. The following are some of my codes:
When a user logs in:
from gaesessions import get_current_session
...
session = get_current_session()
if session.is_active():
session.terminate()
session['account'] = account
# Do some stuff to log the user in
When the user logs out:
session = get_current_session()
account = session['account']
# Do some stuff to log the user out
The above codes worked just fine most of the time, except that sometimes (very rarely, maybe once in a month) GAE complained about the statement account = session['account']
when the user logs out with the error message: KeyError: 'account'
I wonder if anybody has encountered the same problem?
BTW, I also clean up expired sessions as below. Is it necessary? (I have no idea when a session goes expired) Or could it be the cause of the problem? Thanks.
while not delete_expired_sessions():
pass