[mod_python] Sessions: Confused: Newbie

elias.collas at gulfstream.com elias.collas at gulfstream.com
Mon Feb 4 09:04:21 EST 2008


Hi,
I ran into this when I first started messing about with sessions.
Check your apache error_log for session related exceptions. If sessions
aren't properly configured, mod_python may not be able to create or
retrieve the session id.

HTH,
Elias

mod_python-bounces at modpython.org wrote on 02/04/2008 08:19:21 AM:

> I thought I was understanding sessions but the following did not
> work as I expected.
>
> I was expecting the first execution to create a session with a PID
> of 666 and a Hits Value of 1 and on each refresh of that page in the
> same browser to increment the hit counter, but the 'is_new' test,
> returns true every time.  I have tried this on several computers and
> with different browsers, but always the same result.
>
> Where have I gone wrong ?
>
> Richard
>
> MOD_PYTHON, Apache, PYTHON 2.5
>
> Code =====================================
> from mod_python import Session, util
>
> def index(req):
>     main(req)
>
> def main(req):
>     mySess = Session.Session(req)
>     if mySess.is_new():
>         pid = 666
>         mySess['pid'] = str(pid)
>         mySess['hits'] = 1
>         req.write("NEW Session PID: %s <BR>\n" % mySess['pid'])
>         req.write("Hits: %s <br>\n" % mySess['hits'])
>     else:
>         mySess['hits'] +=1
>         req.write("OLD Session PID: %s <BR>\n" % mySess['pid'])
>         req.write("Hits: %s <br>\n" % mySess['hits'])
> _______________________________________________
> 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