From ec607e73754956de385e4f7d5c0367bd967a0299 Mon Sep 17 00:00:00 2001 From: Jordan Milne Date: Wed, 24 Jun 2015 11:58:35 -0700 Subject: [PATCH] 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 --- r2/r2/config/middleware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r2/r2/config/middleware.py b/r2/r2/config/middleware.py index 4fbd24016..6b5e520aa 100644 --- a/r2/r2/config/middleware.py +++ b/r2/r2/config/middleware.py @@ -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):