Flask website often fails to load resources?
Initial situation:
- Flask backend deployed via CGI
- All used resources (CSS, images, videos, etc.) are imported via url_for()
- CGI because it's a rented Strato server, and the "Hosting Basic" package only accepts CGI. (If anyone has any other information about this, please share it.)
Problem:
- In 30% of cases the page loads without problems, all content is loaded and displayed correctly
- In 35% of cases the page loads (including the JS file that removes the loading page after the page has fully loaded) but videos are missing in the background
- In another 35% of cases, the loading screen is displayed, but neither images, videos, CSS files, nor the JS file that removes the loader are loaded, so only the loader is visible.
Console throws error code 500 for each resource
Error Log shows again and again:
End of script output before headers: [NAME].cgi
All files in the cgi-bin folder, i.e. all page-relevant files, have permission 755
Is the server simply overloaded sometimes? Does anyone here have any ideas on what else I can try?
Thank you in advance!
A a few possible sources of error that come to me:
(1) The Python files should contain a Shebang in the first line, which shows the Python interpreter.
For Strato it would be right as follows:
2) Make sure you use a universal character encoding like UTF-8 for your script files. With dos2unix you can make a conversion.
3) A server timeout or a missing response can also cause this error message. You may be able to reproduce this behavior in a local test environment. If so, the problem is more likely in your application.
So and so I would also recommend looking for logs on/to the system.
SELinux, SUexec etc perhaps blame?
Check the corresponding Error Logs! Not only from Apache 😉