[albatross-users] cookie error in sessionfile.py
Sheila King
sheila at thinkspot.net
Tue Jun 3 16:37:22 EST 2003
Today I asked some of the members on my team to test the application I've
been building. It doesn't do a whole lot yet. Mostly authentication stuff.
Create new account. Log in. Log out. Request lost password. Expires after x
minutes of inactivity.
Anyhow, I had tested it on Mozilla 1.3 and 1.0 and IE 5.0 and 6.0 on two
different computers. Never a problem with loading templates and simply
displaying pages.
So I show it to my boss today and first thing, as soon as she goes to the
URL, she gets a traceback. And I look and tell her it is a cookie thing,
and she has them enabled and she fiddled around with her browser, and no
matter what, she couldn't view the app. Just errors and tracebacks. Here is
a sample traceback:
----------------------------------------
Template traceback (most recent call last):
Traceback (most recent call last):
File "/usr/lib/python2.2/site-packages/albatross/app.py", line 142, in run
self.load_session(ctx)
File "/usr/lib/python2.2/site-packages/albatross/app.py", line 204, in
load_session
ctx.load_session()
File "/usr/lib/python2.2/site-packages/albatross/sessionfile.py", line
46, in load_session
sesid = self._get_sesid_from_cookie()
File "/usr/lib/python2.2/site-packages/albatross/sessionfile.py", line
37, in _get_sesid_from_cookie
return os.path.basename(c[self.app.ses_appid()].value)
File "/usr/lib/python2.2/UserDict.py", line 14, in __getitem__
def __getitem__(self, key): return self.data[key]
KeyError: appid
------------------------------------------
In an attempt at resolving this situation, I made the following change in
the sessionfile.py file:
To this function:
(starting at line 32)
------------------------------------------
def _get_sesid_from_cookie(self):
hdr = self.request.get_header('Cookie')
if hdr:
c = Cookie.SimpleCookie(hdr)
try:
return os.path.basename(c[self.app.ses_appid()].value)
except OSError:
pass
return None
------------------------------------------
I simply added one more exception check:
------------------------------------------
def _get_sesid_from_cookie(self):
hdr = self.request.get_header('Cookie')
if hdr:
c = Cookie.SimpleCookie(hdr)
try:
return os.path.basename(c[self.app.ses_appid()].value)
except OSError:
pass
### KeyError fix
except KeyError:
pass
return None
------------------------------------------
and that seems to have solved the problem. By the way, I had two other
people test the app before I made the fix, and they had no problems either.
The person with the issue was using IE 5.5, but two of the other testers
also used that browser, and had no issues.
FWIW, it seems that her browser was sending a cookie. How, I have no idea?
To my knowledge, this person has never before visited the site/directory
where my app was stored. Anyhow, her browser was sending a cookie, but not
one my app had set, and then my app was trying to lookup the cookie by the
appid name, and failing.
So, I just old the app to ignore a KeyError, and it all seems fixed?
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org
More information about the Albatross-users
mailing list