librelist archives

« back to archive

Get the Flask to work with python-fastcgi

Get the Flask to work with python-fastcgi

From:
Динар Рахимбаев
Date:
2013-07-30 @ 16:40
Hello everybody!

I'm new to Flask and using it for a short while.
I deploy applications to web-server through FastCGI.
If I deploy it using wsgi-middleware Flup it works fine. But it doesn't 
if I use another wsgi middleware - python-fastcgi 
(https://pypi.python.org/pypi/python-fastcgi).
Let's look at code snippet below:

=======================================

#!/usr/bin/python

from flup.server.fcgi import WSGIServer      # flup
#from fastcgi import ThreadedWSGIServer      # python-fastcgi

from flask import Flask, request, make_response

app = Flask(__name__)


@app.route('/hello', methods=['GET'])
def hello():
     return make_response('Hello, World!', 200)


if __name__ == '__main__':
     app.debug = True
     application = app

     # flup wsgi server
     WSGIServer(app, bindAddress = '/tmp/flup_proxy.sock', minSpare = 8, 
maxSpare = 8, maxThreads = 8).run()

     # python-fastcgi wsgi server
     #s = ThreadedWSGIServer(app, workers=8)
     #s.serve_forever()

=======================================


When I use Flup as wsgi middleware it works fine. I get 'HTTP/1.1 200 
OK' and see 'Hello, World!' message in browser.
But when I use python-fastcgi it doesn't work.
I get HTTP/1.1 500 Internal Server Error.

What may cause such error?

If I deploy code that doesn't envolve Flask with pyhton-fastcgi it works 
fine
Example:

=======================================

#!/usr/bin/python
from fastcgi import ThreadedWSGIServer      # python-fastcgi

def hello(environ, start_response):
         status = '200 OK'
         output = 'Hello, World!'
         response_headers = [('Content-type', 'text/plain')]
         start_response(status, response_headers)
         return [output]

application = hello
s = ThreadedWSGIServer(hello, workers=8)
s.serve_forever()

=======================================

How can I get the Flask to work with  python-fastcgi?

Thanks!
Best regards Dinar.