2012-01-22 32 views
1

運行gevent的WSGIServer時,出現了一些非常奇怪的行爲。似乎每次自帶通過具有被錯誤解釋它的方法請求..gevent.WSGIServer請求方法mystery

如果我發送了以下請求:

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

回答

1

LIBEVENT對HTTP方法的有限支持和HTTP方法支持依賴於libevent的版本。爲什麼你有一個數字而不是一個方法顯然是一個錯誤。難道你是在建造和連接gevent與不同版本?

你可以嘗試切換到gevent.pywsgi嗎?這將以一些性能爲代價來解決問題。

此外,gevent的1.0版本還有許多重大改進。你可以得到它:http://code.google.com/p/gevent/downloads/list

+1

我使用安裝使用apt-get的gevent版本0.13.0。使用'pywsgi'解決了這個問題,但是我很好奇爲什麼當使用'gevent.wsgi'時爲什麼會出錯。 – Acorn

+1

ubuntu存儲庫有一個gevent的古老版本。升級到最新版本將所有內容整理出來。乾杯! – Acorn