Jeremy Kohansimeh
jkohans at gmail.com
Wed Jul 13 20:30:15 EDT 2005
I should have mentioned that this is done and it is done before any HTML is written to the browser. So, there should not be the problem of having saved the session after some HTML has been written to the browser, which would prevent the cookie from being set. Jeremy On 7/13/05, Jim Gallacher <jg.lists at sympatico.ca> wrote: > > Jeremy Kohansimeh wrote: > > Hello, > > > > I have a problem where I am not able to reinstate an old Session. On > > initial login I record the session id and then check that the pysid > > cookie has been set appropriately in my browser, which it has. But, on > > a subsequent call when I try to reinstate the same session, I get a new > > one back that no longer has any of the items I have saved. I have been > > using the following code for diagnostics: > > > > def handler(req, **kw): > > """handles initial requests""" > > > > # used for debugging > > f = open( '/home/jeremyk/public_html/data/foo.log', 'a+') > > > > cookies = Cookie.get_cookies( req) > > if cookies.has_key( 'pysid'): > > pysid = cookies[ 'pysid'].value > > > > f.write( 'pysid is ' + pysid + '\n') > > req.sess = Session.Session( req, sid=pysid) > > else: > > req.sess = Session.Session( req) > > > > #req.sess = Session.Session( req) > > req.sess.set_timeout( 20 * 60) > > id = req.sess.id() > > > > if not req.sess.is_new(): > > f.write( 'old session: ' + id + '\n') > > else: > > f.write( 'new session: ' + id + '\n') > > > > f.close() > > > > return segment.dispatchToHandler( req) > > > > I know that I do not need to specify the sid attribute of Session for an > > old session to be reinstated (this can be determined from the request > > object), but it wasn't working when I did it that way either. Something > > that seems very strange to me is that the pysid value I get back from > > here does not match the cookie that has been set in my browser. As you > > can see, I set the timeout to 20 minutes, which is much longer than the > > time inbetween the 2 calls. Is there anything else I should try? > > > > In your example code you never save the session data. When you create a > session instance with an explicit sid, Session tries to load the > corresponding session. If that session does not exist a new session id > is created, and thus you see a new pysid on each request. > > You need req.sess.save() somewhere in your code. > > Regards, > Jim > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050713/72b44f32/attachment-0001.html
|