Note that there are some explanatory texts on larger screens.

plurals
  1. POApache with mod_wsgi and python returns 500 periodically
    primarykey
    data
    text
    <p>I have a website running on Python and Flask. 4 times out of 10 it returns a 500 error, randomly as far as I can tell. </p> <pre><code>from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "Hello world!" </code></pre> <p>Here's my .wsgi file (I'm using virtualenv, and activating it before importing the application):</p> <pre><code>activate_this = '/path/to/app/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) from myapp import app as application </code></pre> <p>This is my Apache host configuration:</p> <pre><code>&lt;VirtualHost *:80&gt; ServerName website.com WSGIDaemonProcess myapp user=ubuntu group=ubuntu processes=2 threads=5 WSGIScriptAlias / /path/to/app/myapp.wsgi &lt;Directory /path/to/app&gt; WSGIProcessGroup myapp WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all &lt;/Directory&gt; &lt;/VirtualHost&gt; </code></pre> <p>Any pointers to debug this are welcome!</p> <p><strong>EDIT:</strong></p> <p>Apache error.log:</p> <pre><code>mod_wsgi (pid=29581): Target WSGI script '/path/to/app/myapp.wsgi' cannot be loaded as Python module. mod_wsgi (pid=29581): Exception occurred processing WSGI script '/path/to/app/myapp.wsgi'. Traceback (most recent call last): File "/path/to/app/myapp.wsgi", line 4, in &lt;module&gt; from myapp import app as application ImportError: No module named myapp </code></pre> <p>It seems that one of the two processes (29581) is not running the virtualenv bit, and therefore not locating the files to import.</p> <p><strong>EDIT 2:</strong></p> <p>It's the local file myapp.py that is not being found in the PATH. I needed to include this at the top of my .wsgi file:</p> <pre><code>import sys sys.path.insert(0, '/path/to/myapp') activate_this = '/path/to/myapp/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) from myapp import app as application </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload