Intermitent 500 HTTP errors with Flask and WSGI
I'm trying to setup a Flask application on a machine running Apache and
mod_wsgi. My application runs 'randomly' well, meaning that sometimes it
works and sometimes I refresh it and it throws an Internal Server Error.
It seems quite random.. I have cleared the cache of my browser, tried a
different browser, tried incognito mode, asked a friend to try from his
laptop. It always shows this intermitent 500 behaviour.
Does anyone have any ideas where I can look for the cause? Or maybe you
had this problem before?
All the data I can think of about this is below, let me know if you need
anything else.
Thanks!
The Apache error_log shows the following when the refreshing fails:
[Wed Aug 14 16:42:52 2013] [error] [client 171.65.95.100] mod_wsgi
(pid=1160): Target WSGI script '/home/server/servers/flaskapp.wsgi' cannot
be loaded as Python module.
[Wed Aug 14 16:42:52 2013] [error] [client 171.65.95.100] mod_wsgi
(pid=1160): Exception occurred processing WSGI script
'/home/server/servers/flaskapp.wsgi'.
[Wed Aug 14 16:42:52 2013] [error] [client 171.65.95.100] Traceback (most
recent call last):
[Wed Aug 14 16:42:52 2013] [error] [client 171.65.95.100] File
"/home/server/servers/flaskapp.wsgi", line 5, in <module>
[Wed Aug 14 16:42:52 2013] [error] [client 171.65.95.100] from
flaskapp.frontend import app
[Wed Aug 14 16:42:52 2013] [error] [client 171.65.95.100] ImportError:
cannot import name app
The application is organized like this:
flaskapp.wsgi
flaskapp/
__init__.py (empty)
settings.py
frontend/
__init__.py (app is defined here)
static/
style.css
templates/
index.html
views.py
The init.py contains the following:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object('flaskapp.settings')
db = SQLAlchemy(app)
import flaskapp.views
The configuration file in the Apache httpd.conf file related to this
application is:
<VirtualHost *:80>
ServerName <redacted>
WSGIDaemonProcess flaskapp user=server group=server
WSGIScriptAlias /flaskapp /home/server/servers/flaskapp.wsgi
<Directory /home/server/servers/flaskapp/>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
No comments:
Post a Comment