Session variable lost after redirect on PythonAnywhere but NOT locally

106 views
Skip to first unread message

Dan

unread,
Feb 3, 2016, 4:54:36 PM2/3/16
to web2py-users
I use a session variable to pass some info with a redirect:

    session.OrigText = XML(str(OrigText))
    redirect(URL('SearchResultsOrigText'))

It arrives at the new URL / page / view - SearchResultsOrigText  - and works Ok. 
But when from that new URL - SearchResultsOrigText- I navigate away (and it doesn't matter where I go from this new page), when returning with the 'back" button of the browser, the session.OrigText is now empty (showing as 'None').

This behaviour is happening only on PA and not locally.
I do not use session.forget anywhere in my code.

Trying to pass the 'html heavy' content in the OrigText as a dictionary variable (not a session variable) gets me into another interesting issue...Python Anywhere says "Something's wrong 502- Back End". 
(Silent failing ?) This happens on PythonAnywhere but NOT locally as well.
Sanitizing this var doesn't help...

But let's focus on the first question...Why is the session variable lost after a redirect and then leaving the new page / view 
 when hosted on PythonAnywhere and NOT locally ?

Thanks

Anthony

unread,
Feb 3, 2016, 5:27:26 PM2/3/16
to web2py-users
Using the browser developer tools, on the subsequent navigations, see if (a) the browser is sending the session cookie to the server and (b) the server is sending the same session cookie back. If you are transitioning from http to https and have either set session.secure() or request.requires_https(), the original session cookie will not be returned to the server. Also, if you transition from being logged in to being logged out, the session will be cleared by default.

Anthony
Reply all
Reply to author
Forward
0 new messages