python - Gunicorn(Python3.4 和 3.3)仅在响应中发送没有数据的 header

标签 python python-3.x wsgi gunicorn

我在云中有 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/

相关文章:

python - pandas 系列从十六进制转换为 ascii 时出现错误

python - 哪个是支持代码重新加载的简约 python wsgi 开发服务器?

python - requests.get 到 localhost 超时

Python:带有域检查的线性代数包

python - 在特定点移动名称中具有一位或两位数字的文件

python - 在 PyCharm 中使用 PowerShell 时自动激活 Python venv

python - 如何将函数属性用作 python 对象以及字符串

python-3.x - Python Google Sheets API 通过一次批量更新来更新值和工作表属性

python - 使用 python Flask 应用程序部署到 heroku 时 Procfile/wsgi 出现问题 ~ 找不到属性

python - 从 python3 程序调用 firefox 的正确方法是什么?