[mod_python] Session example and problems.

donnie jones donniejones18 at gmail.com
Fri Feb 25 14:53:28 EST 2005


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
>


More information about the Mod_python mailing list