librelist archives

« back to archive

Get the Flask to work with python-fastcgi

Get the Flask to work with python-fastcgi

Динар Рахимбаев
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 
Let's look at code snippet below:



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)


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 


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)


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

Best regards Dinar.