[mod_python] .save() for sessions not working ...

Adrian Immler mod_python-maillist at uebergeek.de
Mon Feb 21 12:19:01 EST 2005

hello !

[code at the end]
i have reduced my script to a minimum, but somehow only the sess.save()
in the "if" condition works just before the redirect. every later
attempt i am told:

------[ SNIP ]----------------------------------------------
Mod_python error: "PythonHandler mptest"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
    result = object(req)

  File "/usr/local/httpd/htdocs/test/mptest.py", line 42, in handler

  File "/usr/lib/python2.4/site-packages/mod_python/Session.py", line
204, in save

  File "/usr/lib/python2.4/site-packages/mod_python/Session.py", line
329, in do_save
    dbm[self._sid] = cPickle.dumps(dict)

  File "/usr/lib/python2.4/dumbdbm.py", line 160, in __setitem__
    raise TypeError, "keys and values must be strings"

TypeError: keys and values must be strings
------[ SNAP ]----------------------------------------------

so what am i doing wrong ? here is the non-working code:

------[ SNIP ]----------------------------------------------
from mod_python import apache
from mod_python import util
from mod_python.util import FieldStorage
from mod_python import Session

def handler(req):
  req.content_type = "text/html"
  fs = FieldStorage(req)

  sess = Session.Session(req, fs.getfirst("SID"))
  if sess.is_new():
    util.redirect(req,"http://localhost/test/mptest.py?SID=" +
    sess['foo'] = 'spam'

  sess['bar'] = 'eggs'

  return apache.OK

More information about the Mod_python mailing list