1

运行 gevent 的 WSGIServer 时,我遇到了一些非常奇怪的行为。似乎通过的每个请求的方法都被错误地解释了..

如果我发送以下请求:

requests.get('http://localhost:5000')
requests.head('http://localhost:5000')
requests.delete('http://localhost:5000')
requests.put('http://localhost:5000')
requests.post('http://localhost:5000')

这是控制台中显示的内容:

127.0.0.1 - - [2012-01-22 14:55:36] "POST / HTTP/1.1" 405 183 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:55:41] "DELETE / HTTP/1.1" 405 185 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:55:46] "16 / HTTP/1.1" 405 181 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:55:50] "8 / HTTP/1.1" 405 180 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:56:13] "HEAD / HTTP/1.1" 200 0 "-" "python-requests/0.9.1"

为了完整起见,这是我正在运行的脚本:

from gevent.wsgi import WSGIServer
from flask import Flask

app = Flask(__name__)
app.debug = True

@app.route("/")
def hello():
    return 'hello'

port = 5000

http_server = WSGIServer(('', port), app)
http_server.serve_forever()

会发生什么?

编辑:

我正在使用 gevent 版本:0.13.0

4

1 回答 1

1

Libevent 对 HTTP 方法的支持有限,支持哪些 HTTP 方法取决于 libevent 版本。为什么你有一个数字而不是一个方法显然是一个错误。是不是您正在构建 gevent 并将其链接到不同的版本?

您可以尝试切换到 gevent.pywsgi 吗?这将以牺牲一些性能为代价来解决问题。

gevent 的 1.0 版本也有许多很大的改进。你可以在那里得到它:http ://code.google.com/p/gevent/downloads/list

于 2012-01-22T18:07:22.647 回答