Question

I have been reading the guide here but I have been unable to deploy Flask on Bluehost.

Here are the packages installed in the venv:

Flask           - 0.10.1       - active 
Jinja2          - 2.7.2        - active 
MarkupSafe      - 0.21         - active 
Python          - 2.7.3        - non-active development (/usr/local/lib/python2.7/lib-dynload)
Python          - 2.7.6        - active development (/usr/local/lib/python2.7/lib-dynload)
Werkzeug        - 0.9.4        - active 
flup            - 1.0.2        - active 
itsdangerous    - 0.24         - active 
pip 1.5.4 has no metadata
setuptools 2.2 has no metadata
wsgiref         - 0.1.2        - active development (/usr/local/lib/python2.7)
yolk            - 0.4.3        - active

My .htaccess file in public_html:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L]

The flask_hello_world.fcgi, also in public_html:

    #!/home/REDACTED/venv/flask_hello_world/bin/python

    from flup.server.fcgi import WSGIServer
    from flask_hello_world_app import app as application

    WSGIServer(application).run()

The flask_hello_world_app.py file, also in public_html:

from datetime import datetime
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/the-time')
def the_time():
     cur_time = str(datetime.now())
     return cur_time + ' is the current time!  ...YEAH!'

if __name__ == '__main__':
    app.run()

Output is as follows when executing flask_hello_world.fcgi:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 12

Hello World!Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr

Output is as follows when executing flask_hello_world.fcgi with python interpreter:

  Traceback (most recent call last):
  File "flask_hello_world.fcgi", line 4, in <module>
    from flask_hello_world_app import app as application
  File "/home/REDACTED/public_html/flask_hello_world/flask_hello_world_app.py", line 2, in <module>
    from flask import Flask
  File "/usr/lib/python2.6/site-packages/flask/__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
ImportError: No module named jinja2

The Apache error log is as follows:

[Tue Apr 22 19:56:19 2014] [warn] [client xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Tue Apr 22 19:56:19 2014] [error] [client xxx] Premature end of script headers: flask_hello_world.fcgi
[Tue Apr 22 19:56:19 2014] [error] [client xxx] exec used but not allowed in /home/REDACTED/public_html/500.shtml

I have successfully deployed Flask in the past, so I am kind of at a loss at this point. I suppose that I am missing something simple, and any help would be appreciated.


Edit: It was a permissions / ownership issue which I found my examining the suexec logs.

Was it helpful?

Solution

Aside from the obvious is Jinja2 REALY installed, my bet is your mod_wsgi isn't finding your virtualenv. That would explain the Jinja2 environment errors.

At the VERY bottom of the mod_wsgi(Apache) deployment doc

If you want to use a virtual environment with mod_wsgi you have to modify your .wsgi file slightly.

Add the following lines to the top of your .wsgi file:

activate_this = '/path/to/env/bin/activate_this.py'

execfile(activate_this, dict(file=activate_this))

This sets up the load paths according to the settings of the virtual environment. Keep in mind that the path has to be absolute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top