From c3ff8fbfb1578d7c2590690dd24a09c1789ed7de Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 29 Jan 2015 08:48:51 +0000 Subject: [PATCH] Make sure JSON output are byte strings. This works around https://code.djangoproject.com/ticket/24240 which otherwise dies when trying to cope with a StreamingHttpResponse containing unicode strings. --- mapit/shortcuts.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mapit/shortcuts.py b/mapit/shortcuts.py index e95c67ce..6295962b 100644 --- a/mapit/shortcuts.py +++ b/mapit/shortcuts.py @@ -6,6 +6,8 @@ from django.shortcuts import get_object_or_404 as orig_get_object_or_404 from django.shortcuts import render_to_response from django.template import RequestContext +from django.utils.six.moves import map +from django.utils.encoding import smart_str from django.core.serializers.json import DjangoJSONEncoder # Assuming at least python 2.6, in Django < 1.6, the above class is either a @@ -60,6 +62,7 @@ def output_json(out, code=200): indent = 4 encoder = GEOS_JSONEncoder(ensure_ascii=False, indent=indent) content = encoder.iterencode(out) + content = map(smart_str, content) # Workaround Django bug #24240 types = { 400: http.HttpResponseBadRequest,