gevent fastcgi standalone无法正常工作?

时间:2017-12-14 11:03:16

标签: python cgi fastcgi gevent

如本页https://pypi.python.org/pypi/gevent-fastcgi所示, 我们可以在独立模式下使用gevent-fastcgi。

from gevent_fastcgi.server import FastCGIServer
from gevent_fastcgi.wsgi import WSGIRequestHandler

def wsgi_app(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/plain')])
    yield 'Hello World!'


request_handler = WSGIRequestHandler(wsgi_app)
server = FastCGIServer(('127.0.0.1', 4000), request_handler, num_workers=4)
server.serve_forever()

但是,当我用wget尝试它时,它会被阻止。

$ wget http://127.0.0.1:4000/ping
Connecting to 127.0.0.1:4000... connected.
HTTP request sent, awaiting response...

Python2.7.10,gevent-fastcgi == 1.0.2.1,gevent == 1.2.1

代码有什么问题吗?感谢

1 个答案:

答案 0 :(得分:1)

gevent-fastcgi is a library to serve WSGI app via fastcgi protocol, but wget is trying to talk with HTTP, you need another server in front of "127.0.0.1:4000" to translate HTTP to fastcgi, like nginx.