Forums

MySQL and Virtual Environments

I have an app which uses a MySQL database which has been initialized in a virtual environment. It works fine, except that on first load the webapp will sometimes fail to render and instead display the "Coming soon!" PythonAnywhere page. Simply refreshing it will always allow it to render the page, but its very annoying to users.

Are you guys aware of this issue and is there any way to resolve it?

That has nothing to do with MySQL or virtual environments. The most likely cause of that is that you have a redirect of some sort that may be going to a non-existent address sometimes. What address are you going to when you get the "Coming soon" page and what address is shown in the address bar when the "Coming soon" page is shown?

I created an app with a MySQL db in the same virtual environment as another app. If I migrate/upgrade either of the two apps, (both called db in their respective folders), the eavsdrop app (which uses MySQL instead of SQLite) will cause the url https://www.eavsdrop.com/ to redirect to "Something went wrong :-( Something went wrong while trying to load this website; please try again later." The only reason I thought it had something to do with the database was because it only happens when a migration/upgrade occurs.

"Something went wrong" means that your app is crashing -- check the error logs for more details and see what's failing.

These are three snippets of the generated error I found relevant

2023-10-26 04:14:40,367: Error running WSGI application
2023-10-26 04:14:40,379: sqlalchemy.exc.OperationalError: (mysql.connector.errors.OperationalError) MySQL Connection not available.
...
2023-10-26 04:14:40,380: FROM drops ORDER BY drops.created_at DESC]
2023-10-26 04:14:40,380: [parameters: [{}]]
2023-10-26 04:14:40,381: (Background on this error at: https://sqlalche.me/e/20/e3q8)
...
2023-10-26 04:14:40,410:   File "/home/bbwerth/.virtualenvs/stockle/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 700, in cursor
2023-10-26 04:14:40,410:     raise OperationalError("MySQL Connection not available.")

Do you think some of the solutions mentioned in the link below could be used to fix it?

https://docs.sqlalchemy.org/en/20/core/pooling.html#pool-disconnects (mentioned as solutions to Operation Errors in https://sqlalche.me/e/20/e3q8)

See https://help.pythonanywhere.com/pages/UsingSQLAlchemywithMySQL/