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

Adrian Immler mod_python-maillist at uebergeek.de
Tue Feb 22 05:13:06 EST 2005


>Mmm reducing the script isn't helpful, because something you are doing 
>could inadvertently affect it.
it is reduced to a version that still produces the same error ...

>But it might be that you're saving an 
>empty session?   Dunno.  Which save does it break on?
it breaks at any of the (now commented) sess.safe(), if i uncomment one
of the two sess.save()'s it breaks up ....

----------------------------------------------------------------------
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():
    sess.save()
    util.redirect(req,"http://localhost/test/mptest.py?SID=" +
sess.id())
  else:
    1+1
    sess['foo'] = 'one'
#    sess.save()

  sess['bar'] = 'two'
#  sess.save()
  return apache.OK


--------------------------------------------------
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 22, in handler
    sess.save()

  File "/usr/lib/python2.4/site-packages/mod_python/Session.py", line
204, in save
    self.do_save(dict)

  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



More information about the Mod_python mailing list