3

I'm at a loss here...

I'm trying to use uwsgi to run my flask app. Using the example at WSGI Quick Start I get it to run.

For development (restserver.py):

 from api import app

 if __name__ == '__main__':
     app.run(debug=True, port=8080)

How would I start the uwsgi server with this?

I have tried this (restserver.fcgi):

#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from api import app

if __name__ == '__main__':
    WSGIServer(app, bindAddress='/var/run/fcgi.sock').run()

but when reading more I see that uwsgi want's to call the method application by default. I can change that of course but I don't have and application method so when running:

/usr/local/bin/uwsgi --http :9090 --wsgi-file restserver.fcgi

I get the following message in the start log:

unable to find "application" callable in file restserver.fcgi
1
  • Have you edited your uwsgi.ini file? I was configuring nginx with uswsgi and flask recently, and it was painful, but I managed to do this, one thing I remember is that you need to specify callable in your uwsgi.ini file, you should specify app as callable there, and it should fix this error. I have something like this there: callable = app. There is also an option touch-reload, and I have there a path to runserver.py touch-reload = /home/###/bla/bla/run.py. Hope this helps somehow. Commented Aug 9, 2013 at 9:44

1 Answer 1

3

All you need is to change start command to

/usr/local/bin/uwsgi --http :9090 --wsgi-file restserver.fcgi --callable app

or change the way you import your flask application in restserver.fcgi to

#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from api import app as application

if __name__ == '__main__':
    WSGIServer(application, bindAddress='/var/run/fcgi.sock').run()

Docs on using uWSGI with Flask

PS: Actually your flask app is WSGI application.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. I realized that minutes after I'd posted the question. I was looking at fast-cgi before hence the restserver.fcgi. Now I can just use the normal restserver.py file to start it.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.