Sessions in Flask

Deploying a python flask app on R-studio

Hi Everyone. My colleague and I skilled up over the past year on R and Python respectively. We like the RStudio environment and that we can have python and R scripts living in the same place.

I have developed a python web-app using Flask which we managed to successfully deploy on R Studio. I have previously also deployed in on Digital Ocean without a hitch. The coding that went into this was substantial and the app is really useful to us.

The problem I encounter here on RStudio however, is that any flask route that makes use of a 'session' variable check (created in the app itself - not a R studio 'session' variable), results in a "404 Not Found Error". So whenever the app makes a call on a particular route that goes through a session check, it results in the "404 Not Found Error". The route calls that do not make use of a session variable works without a hitch.

This is a bit of a show-stopper because the bulk of the app relies on the session variables unique to each user that make use of the app. My understanding was that this can be accommodated on Rstudio. The target number of users for this app is less than 20. To abandon the session variables is not really a sensible option right now because these variables are interwoven and fundamental to most aspects of the app. A re-write basically. Not something I am particularly keen to do. Has somebody encountered this issue before and what was your solution? I would really appreciate help on this. We desperately want this python flask web-app to work.
Thanks in advance!

We've seen on occasion where a customer wrote a flask app and set session variables in a way that didn't persists across processes.

The mental model is that every flask response could be handled by a different process on Connect, so you need to set your session variables in a way that is process-independent.

You may want to consider using cookies to set persistent user session variables.

Also, a minimal reproducible example of a flask app that causes your observed behaviour will be valuable. Can you provide such a minimal reprex? (I'm trying to do the same and find an example app that demonstrates how to set session variables correctly.)

You may find this article at Sessions in Flask helpful.

We used the worked example and deployed this into Connect at - you should be able to interact with this session-based flask app there.

Thank you Andrie, the Sessions in Flask article particularly pertaining to the client side session is exactly what I am doing. To be clear, it works locally, it worked on Digital Ocean's platform. So coding and handling the sessions are not the problems. The problem is that it does not seem to work on Rstudio when I use client side sessions. I immediately get a 404.

On the link ... I get a 404 there as well when I click on the link?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.