Forums

Flask app showing data from the previous user

Hi and sorry if this has been asked before (didn't find a similar problem when browsing through).

I have a flask app that uses spotipy to display tracks from Spotify playlists. The user should be able to give ratings to the tracks in the playlist. Locally everything is working fine, but when I put the app on PA the user of the app will see data from the previous user. To be specific they'll see songs from a previous playlist posted by another user.

I have no idea if this is a PA problem or if there is something wrong with my code, but I would like all users, in fact all visits to start clean.

Hope this makes sense.

Thanks in advance.

Take a look at https://help.pythonanywhere.com/pages/GlobalStateAndWebApps/

Thank you. I tried adding session.clear(), but the issue is still there. Have to do some more research.

Maybe add some logging to your code to see how the state changes in correlation with incoming requests.

Sorry, I have no idea how to do that.

Thanks anyway.

Very basic logging would consists on print calls -- the only think you need to add is the redirection to the standard error, if you want to see the logs in the error log rather than in the server log. It could be something like:

import sys

print("A message", file=sys.stderr)

You probably want to add logging in different places to see how the state changes during the execution.

Thank you so much for taking the time to reply.

Could this, as printed in the error log, be the source of the problem?

2022-03-17 22:18:13,897: Couldn't read cache at: .cache 
2022-03-17 22:18:13,962: Couldn't write token to cache at: .cache

I'm not sure what you're printing exactly, and what you're trying to log, so it's hard to tell.

This is the error log and the message it prints whenever I use the web app.

But is it a result of your logging or is it an error from your code? If it's the latter -- are there more errors? Is there a context for those errors? Maybe you should check whether you're trying to read/write into ".cache"?