【问题标题】:gevent.WSGIServer request method mysterygevent.WSGIServer 请求方法之谜
【发布时间】:2012-01-22 15:24:45
【问题描述】:

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

【问题讨论】:

    标签: python gevent http-method


    【解决方案1】:

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

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

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

    【讨论】:

    • 我正在使用使用 apt-get 安装的 gevent 0.13.0 版。使用pywsgi 解决了这些问题,但我很好奇为什么使用gevent.wsgi 时会出现如此错误......
    • ubuntu 存储库有一个古老版本的 gevent。升级到最新版本解决了所有问题。干杯!
    猜你喜欢
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 2010-12-22
    相关资源
    最近更新 更多