uWSGI Returning Empty Response


I had the some problem, it turned out that my wsgi application was returning UNICODE instead of BYTE STRINGS (I was on python3) ; and nothing showed in logs about it... WSGI expects byte strings in output, never unicode.

In the callable of your application instead of return "string" you should use return b"string" or return "string".encode("utf-8")

def application(env, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    # One of the below can be used.
    return "string".encode("utf-8")
    return b"string"

You can check http://uwsgi-docs.readthedocs.io/en/latest/Python.html#python-3 out for more informaiton on using uwsgi with python3.


Related videos on Youtube

Author by


I'm a entrepreneur and technical architect at D4 Software. I work with Python and .net.

Updated on September 18, 2022


  • mmrobins
    mmrobins 9 months

    I have a Django site which I am trying to server via uWSGI. I have started the server like so:

    uwsgi --emperor .
    bg 1

    (There are two .ini files which point to the test version and production version of the site, serving on 9001 and 9002 respectively)

    I then attempt to get my site:

    curl http://localhost:9002

    When I do that, I get a message saying the the vassel is loyal but no actual response. The uwsgi.log then contains the following:

    [pid: 5071|app: 0|req: 2/2] () {26 vars in 357 bytes} [Tue Jul 23 13:20:21 2013] GET / => generated 0 bytes in 1 msecs (HTTP/1.1 302) 2 headers in 96 bytes (1 switches on core 1)

    No errors are logged.

    I should say, this worked fine prior to a reboot so the uwsgi.ini files should be fine.

    Any ideas where I should start diagnosing this?

    • Dakota
      Dakota about 9 years
      I can report a similar issue but with an even more basic configuration. Headers are sent properly, but the response body is simply empty. I experience this with Python 3.4 both uWSGI and gunicorn.
    • ThorSummoner
      ThorSummoner over 7 years
      tail the uwsgi log and read it very carefully, its a verbose annoyance but I was able to eventually track down my issue, I was missing the plugin = python3 stanza from my uwsgi vassal's ini, Which in turn meant my python3 django project wasn't actually being loaded or run correctly,
  • AmirHossein
    AmirHossein almost 6 years
    +1 This helped me. I was getting empty response from python3 virtualenv + uwsgi + nginx stack. return ["hello world"] should be return [b"hello world"] more info on: uwsgi-docs.readthedocs.io/en/latest/Python.html