Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gunicorn (Python3.4 and 3.3) sends in response only headers without data

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

like image 565
Dmitry Tabakerov Avatar asked Apr 09 '14 21:04

Dmitry Tabakerov


1 Answers

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.

like image 103
Lugal Avatar answered Nov 16 '22 00:11

Lugal