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

Wagner,Harry wagnerh at oclc.org
Tue Feb 22 08:31:02 EST 2005


Just a guess, but maybe change the line:

 sess = Session.Session(req, fs.getfirst("SID"))

to:  sess = Session.Session(req, str(fs.getfirst("SID"))) 

I hope that helps! 
harry

-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of Adrian Immler
Sent: Tuesday, February 22, 2005 5:13 AM
To: ModPython Maillist
Subject: Re: [mod_python] .save() for sessions not working ...

>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

_______________________________________________
Mod_python mailing list
Mod_python at modpython.org
http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list