[mod_python] Session example and problems.

Chris Jackson christopher.jackson at gmail.com
Fri Feb 25 16:31:43 EST 2005


This is not quite the same as in the example in the URL.

The example in the URL passes the sessid to an <input hidden...> field
via PSP templates.  And when a function like (def UseSession) is
called, req.form['sessid'] stores the value from this hidden field. 
That's how the sessid is passed.

In your GetSid function, you simply say req.write, which doesn't
really do anything but display it, vs. <input hidden...> which
captures the sessid to be used later.  After GetSid ends, your session
id is lost.

~= Chris =~


On Fri, 25 Feb 2005 14:53:28 -0500, donnie jones
<donniejones18 at gmail.com> wrote:
> def GetSid(req, sid=""):
>   sess = Session(req);
>   if sess.is_new():
>     sess['u']="user";
>     sess['p']="password";
>     sid = sess.id();
>     sess.save;
>   else:
>     sid = sess.id();
>   req.write("%s" % sid);
>   return;
> 
> # list mailboxes
> def UseSession(req, sid=""):
>   req.write("%s" % sid);
>   sess = Session(req, sid, None, 1800, 0);
>   if sess.is_new():
>     req.write("<br/>session new<br/>");
>     sid = sess.id();
>   else:
>     sess.load();
>   req.write("%s" % sid);
> 
> I first call the GetSid from my javascript and I am using
> XmlHttpRequest that gets the sid from the responseText.
> Then I call UseSession function with the sid passed to it
> through the javascript, and I print the sid to make sure the
> correct id was passed and that works, but after the Session()
> is ran it always creates a new session,
> I am not sure why... I used this link
> http://www.modpython.org/pipermail/mod_python/2005-January/017111.html
> as an example to follow...
> 
> Any ideas?
> Thanks.
> 
> __
> Donnie
> 
> 
> On Thu, 24 Feb 2005 15:36:43 -0600, Shawn Harrison <harrison at tbc.net> wrote:
> > donnie jones wrote [02/24/05 2:55 PM]:
> > > Hello,
> > >
> > > Could someone please give me an example of using the Session()
> > > in modpython for passing data between functions?
> > > I have been googling, but with no success..
> > >
> > > The problem I am having is that each time I reload a page that calls
> > > the function like below, it creates a new session.
> > >
> > > def test(req):
> > >   sess = Sess(req);
> > >   sid = sess.id();
> > >   if sess.is_new():
> > >     req.write("new session %s" % sid);
> > >   else:
> > >     sess.load();
> > >     req.write("%s" % sess['username']);
> > >
> > > I am printing the session id and each time the function is loaded
> > > I get a new session id, thus I cannot store data in the session
> > > to use in other functions...
> >
> > class BaseSession(req[, sid, secret, timeout, lock, lockfile])
> > ..
> >      save()
> >          This method writes session values to storage.
> >
> > It doesn't appear that you are doing this. It only writes the data when
> > you tell it to.
> >
> > Shawn Harrison
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> >
> _______________________________________________
> 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