[mod_python] Another sessions problem...

Clodoaldo clodoaldo.pinto.neto at gmail.com
Wed Mar 26 14:42:17 EDT 2008


2008/3/26, Dominique.Holzwarth at ch.delarue.com
<Dominique.Holzwarth at ch.delarue.com>:
> Hello everyone
>
>  I've already did some testing with mod_python's session mechanism and so far it seemed to work nice. My latest test case doesn't work at all tho...
>
>  I have to scripts, sessiontest1.py and sessiontest2.py, both are directly in my "python-root" (the folder the publisher handler is using)
>
>  Sessiontest1.py:
>  **************************************************
>  from mod_python import Session
>  import sessiontest2
>
>  secretText = "mysecret"
>
>  def index(req):
>   myClassObject = sessiontest2.myClass()
>   msg = myClassObject.add()
>   req.session = Session.FileSession(req)
>   req.session['test'] = 5
>   req.session['meinKlassenObjekt'] = myClassObject
>   req.session.save()
>   return myClassObject.show(req.session.id())
>
>  **************************************************
>
>  Sessiontest2.py
>  **************************************************
>  from mod_python import Session
>
>  secretText = "mysecret"
>
>  def index(req):
>     req.session = Session.FileSession(req)
>     if req.session.is_new():
>         return "Session is new: "+req.session.id()
>     else:
>         lala = req.session['test']
>         myClassObject = req.session['meinKlassenObjekt']
>         newVal = req.form.getfirst('button')
>         cnt = myClassObject.add(newVal)
>         req.session['meinKlassenObjekt'] = myClassObject
>         req.session.save()
>         return cnt
>     return "default return"
>
>  class myClass:
>     def __init__(self):
>         self.counter = 0
>
>     def add(self, val=1):
>         self.counter = self.counter + val
>         return self.counter
>
>     def show(self, *value):
>         msg = """
>  <html><body>
>  <form action='/python/sessiontest2.py' method='post'>
>     <input name='counter' type='text' readonly value='%s'/>
>     <input name='new' type='text' />
>     <input name='button' type='submit' value='Add' />
>  </form>
>  <p>ID: %s</p>
>  </body></html>
>         """ % (self.counter, value)
>         return msg
>  ****************************************************
>
>  Here's what's happening:
>
>  I call the sessiontest1.py which creates a new session (for a fresh browser window), does some stuff with the class-object, saves the object (resp. the session) and then it returns the html site generated from that class.
>  When I submit that form the sessiontest2.py script is called and in my opinion it should load the previously created session (and do the stuff inside the 'else'). However, it always creates a new session instead of using the old one...
>
>  Maybe anyone got an idea what could be wrong? Would be really nice!

The session id must somehow be saved at the client. A cookie, a
querystring or a hidden field could be used. Where does your code save
and retrieve the session id at/from the client?

Regards, Clodoaldo Pinto Neto


More information about the Mod_python mailing list