我在云中有 vm,python 3.3(也尝试过 3.4 - 结果相同)和 Gunicorn 18。 我复制/粘贴“hello world”应用程序 (app.py):
def app(environ, start_response):
data = "Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
然后运行
gunicorn -w 4 -b 0.0.0.0:8000 app:app
workers 开始没有错误,但是当我尝试用浏览器打开它时,我只得到没有正文的标题:
Connection: "close"
Content-Length: "14"
...and so on
如果我添加一些自定义 header ,我会在响应中得到它,但没有响应正文。 请帮忙
最佳答案
添加到 Graham 的解释中,替换
return iter([data])
与
return [bytes(data, 'utf-8')]
在 Python 3 下为我工作。当我也有它时,它解决了同样的问题。
关于python - Gunicorn(Python3.4 和 3.3)仅在响应中发送没有数据的 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22974024/