python - gevent.WSGIServer请求方法之谜

标签 python gevent http-method

运行 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

最佳答案

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

您可以尝试切换到 gevent.pywsgi 吗?这将解决问题,但会牺牲一些性能。

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

关于python - gevent.WSGIServer请求方法之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8962141/

相关文章:

python - 无法为 xml 下载创建 HttpResponse,Django

python - 如何正确设置 pandas tz_localize?

python - 在Python中与无限循环一起运行服务器

python - Pika 和 gevent 的随机超时错误

php - Silex - 选项方法

c# - ASP.NET MVC 2 中的 httppost、httpput 等属性如何工作?

python - python 中的列表是不可变的吗?它们是在函数中传递值吗?

django - 什么是与Django搭配使用的最佳socket.io服务器-gevent或tornadio2?

python - 如何为 greenlet 指定名称

http - 如何使用Electron在具有复杂媒体类型的HTTP帖子中绕过预检?