Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top