문제

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

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top