Forums

Session variable lost on PythonAnywhere Web2Py after redirect, but NOT locally

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 ?) Sanitizing this var doesn't help...

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

Thanks

Flask sessions, by default use cookies, so it's possible that somewhere in your settings you have a setting for what domain to set the cookies on and that is not set correctly. It's also possible that you haven't set a secret key for sessions.

It is Web2Py and not Flask.

And it gets interesting...bug doesn't appear consistently: sometimes session is lost and sometimes on same network it is kept.

Hmm. When really weird stuff happens with cookies, I tend to suspect browser plugins. Any possibility that an ad-blocker or something is getting confused?