7

Using uWSGI to serve a simple wsgi app, (a simple "Hello, World") my configuration works, but when I try to run a Flask app, I get this in uWSGI's error logs:

current working directory: /opt/python-env/coefficient/lib/python2.6/site-packages
writing pidfile to /var/run/uwsgi.pid
detected binary path: /opt/uwsgi/uwsgi
setuid() to 497
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 2.6.6 (r266:84292, Jun 18 2012, 14:18:47)  [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)]
Set PythonHome to /opt/python-env/coefficient/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xbed3b0
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
added /opt/python-env/coefficient/lib/python2.6/site-packages/ to pythonpath.
unable to find "application" callable in file /var/www/coefficient/flask.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***`

Note in particular this part of the log:

unable to find "application" callable in file /var/www/coefficient/flask.py

unable to load app 0 (mountpoint='') (callable not found or import error)

******no app loaded. going in full dynamic mode******

This is my Flask app:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World, from Flask!"

Before I added my Virtualenv's pythonpath to my configuration file, I was getting an ImportError for Flask. I solved this though, I believe (I'm not receiving errors about it anymore) and here is my complete configuration file:

uwsgi:
  #socket: /tmp/uwsgi.sock 
  socket: 127.0.0.1:3031
  daemonize: /var/log/uwsgi.log
  pidfile: /var/run/uwsgi.pid
  master: true
  vacuum: true
  #wsgi-file: /var/www/coefficient/coefficient.py
  wsgi-file: /var/www/coefficient/flask.py
  processes: 1
  virtualenv: /opt/python-env/coefficient/
  pythonpath: /opt/python-env/coefficient/lib/python2.6/site-packages

This is how I start uWSGI, from an rc script:

/opt/uwsgi/uwsgi --yaml /etc/uwsgi/conf.yaml --uid uwsgi

And if I try to view the Flask program in a browser, I get this:

**uWSGI Error**

Python application not found

Any help is appreciated.

2 Answers 2

14

unable to find "application" callable in file /var/www/coefficient/flask.py

is the key :)

Your app is defining an 'app' callable, so you have to instruct uWSGI to search for it, instead of 'application'.

You can use the option

callable: app

and it will works (this is explained in official Flask docs)

2
  • You're correct: setting callable: app fixed it, and as you said, this in the Flask docs. Strangely, though, on another uWSGI install, using the same Python code, I did not have to specify callable: app; it just worked out of the box.
    – skyler
    Aug 1, 2012 at 14:41
  • Where do I set this value of callable: app? In flask.py? Feb 8, 2017 at 22:56
5

Alternatively, you can add module = flaskapp:app to your ini.

Also, indeed, callable is addressed in uwsgi-docs more clearly:

Flask exports its WSGI function (the one we called “application” at the beginning of this quickstart) as “app”, so we need to instruct uWSGI to use it: uwsgi --wsgi-file myflaskapp.py --callable app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.