Gunicorn (Python3.4 and 3.3) only returns headers without data

I have vm in the cloud, python 3.3 (also tried with 3.4 - the same result) and Gunicorn 18. I copy / paste the "hello world" application (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

the workers started without errors, but when I tried to open it in a browser, I only get headers without a body:

Connection: "close"
Content-Length: "14"
...and so on

If I add some kind of custom header, I will get it in response, but I will not answer. Please, help

+4
source share
2 answers

WSGI Python 3 . , (unicode python 3) . iter() , .

+5

,

return iter([data])

return [bytes(data, 'utf-8')]

Python 3. , .

+11

Source: https://habr.com/ru/post/1535827/


All Articles