Fix 500 error on overly-large API request body

Paster doesn't mind unicode responses, but gunicorn wants byte strings
only:

    Error handling request
    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 131, in handle_request
        resp.write(item)
      File "/usr/lib/python2.7/dist-packages/gunicorn/http/wsgi.py", line 283, in write
        assert isinstance(arg, binary_type), "%r is not a byte." % arg
    AssertionError: u'{' is not a byte.

See https://gist.github.com/JordanMilne/4a7d1b5eb317e607479b for repro
This commit is contained in:
Jordan Milne
2015-06-24 11:58:35 -07:00
parent 35fa8149d5
commit ec607e7375

View File

@@ -317,7 +317,7 @@ def _wsgi_json(start_response, status_int, message=""):
"error": status_int,
"message": message
})
return filters.websafe_json(data)
return [filters.websafe_json(data).encode("utf-8")]
class LimitUploadSize(object):