Your code is not a valid WSGI application for Python 3 for a start. It must return an iterable over byte strings, not native (unicode in python 3) strings. Using iter() is also redundant, return the list directly.
Gunicorn (Python3.4 and 3.3) sends in response only headers without data
-
30-06-2023 - |
题
I have vm in cloud, python 3.3 (also tried with 3.4 - same result) and Gunicorn 18. I copy/paste 'hello world' app (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])
then run
gunicorn -w 4 -b 0.0.0.0:8000 app:app
workers started without errors, but when I tried to open it with browser I get only headers with no body:
Connection: "close"
Content-Length: "14"
...and so on
If I add some custom header I'll get it in response but no response body. Please help
解决方案 2
其他提示
To add to Graham's explanation, replacing
return iter([data])
with
return [bytes(data, 'utf-8')]
works for me under Python 3. That solved the same problem when I had it too.
不隶属于 StackOverflow