talesaz Posted Monday at 09:39 PM Posted Monday at 09:39 PM Hi guys, I’m getting a 500 Internal Server Error when running an application written in Python with Flask. Is there any tool on Heliohost that allows viewing logs or troubleshooting to identify the cause of the error? Thanks! Quote
wolstech Posted 23 hours ago Posted 23 hours ago There's a Logs option in Plesk that show Python errors...they're a bit hard to read because of how Plesk formats them,. but the whole thing including the trace is there. The last line kind of explains it though...your error is this: ModuleNotFoundError: No module named 'pymysql' The modules available on Tommy are shown here: https://krydos1.heliohost.org/pyinfo/info3.12.py You can also request that module be added if you need it. Quote
talesaz Posted 18 hours ago Author Posted 18 hours ago I am encountering an intermittent issue with my Flask application using Flask-SQLAlchemy. The application works for a while, but after refreshing the page a few times, it throws the following error: RuntimeError: Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set. Error Context: The error appears in the Apache logs as follows: mod_wsgi (pid=3543435): Exception occurred processing WSGI script '/home/talesaz.heliohost.us/httpdocs/bma/flask.wsgi'. RuntimeError: Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set. What I Have Tried: 1) Direct Configuration in config.py: I am not using .env files anymore. All configurations are directly set in config.py. 2) Database Connection Test: I added a test in run.py to check the database connection. 3) Error Handling: I added a generic error handler to capture unexpected exceptions. Behavior Observed: - The application works initially and connects to the database successfully. - After refreshing the page a few times, the error appears. - Refreshing the page again sometimes resolves the issue temporarily. - When running the application locally (on my machine) and connecting to the same MySQL database hosted on HelioHost, everything works perfectly without any issues. - The problem only occurs when the application is hosted directly on HelioHost. Quote
wolstech Posted 11 hours ago Posted 11 hours ago Krydos might have more of an idea about why this would happen. I'm not terribly familiar with Python...escalating. Quote
Krydos Posted 5 hours ago Posted 5 hours ago Did you request WSGI restart access? Quote Multiple Apache processes are running on the server, and each time you refresh your site you are randomly assigned to one of these processes. If that particular process has already displayed your site, it shows the cached version of your code; otherwise, it shows the new code changes. This means that during the first 2 hours after a site change, you may intermittently see old or new content, depending on which process you get assigned to. This situation will resolve when Apache is restarted, which happens every 2 hours. Source: https://wiki.helionet.org/Flask#WSGI_Uses_Caching Quote
talesaz Posted 5 hours ago Author Posted 5 hours ago 33 minutes ago, Krydos said: Did you request WSGI restart access? Source: https://wiki.helionet.org/Flask#WSGI_Uses_Caching Sorry, I didn’t read this article earlier, so I didn’t restart. Could you grant me WSGI Control Access? My username is talesaz, and my URL is talesaz.heliohost.us:https://talesaz.heliohost.us/bma. Quote
Krydos Posted 4 hours ago Posted 4 hours ago WSGI control access has been enabled on the domain talesaz.heliohost.us. To restart your Flask app and load new code changes in simply edit /home/talesaz.heliohost.us/httpdocs/bma/flask.wsgi. Adding a blank line, removing a blank line, adding a space, or removing a space are examples of editing the file. As long as the last modified timestamp changes it will clear the server cache. Let us know if you run into any issues. If you get a 500 error check the error logs, and if there isn't much useful information in there let us know and we may be able to get some more logs for you. Plesk isn't very good at filtering Flask logs into the right user accessible logs. At least with WSGI restart access you won't get 500 errors from bugs that you've already fixed, which is very confusing and frustrating. Quote
talesaz Posted 47 minutes ago Author Posted 47 minutes ago Now it works! Thank you so much! Sometimes the website still shows a 500 Internal Server Error, but much less frequently than yesterday, and refreshing the page usually resolves it. The logs don’t provide much information about how to address the issue: 2025-04-15 23:28:23 Error 186.205.7.186 500 GET /bma/flask.wsgi/usuarios/cadastrar HTTP/1.0https://talesaz.heliohost.us/bma/flask.wsgi/conteudo Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 1000 Apache SSL/TLS access 2025-04-15 23:28:25 Access 186.205.7.186 200 GET /bma/flask.wsgi/usuarios/cadastrar HTTP/1.0https://talesaz.heliohost.us/bma/flask.wsgi/conteudo Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 10.8 K Apache SSL/TLS access If you could provide more detailed logs for this event at this timestamp, I would greatly appreciate it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.