Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

UnicodeDecodeError in Python 2.7 for non-200 OK response #794

Open
StenAkeStrid opened this issue Feb 7, 2019 · 0 comments
Open

UnicodeDecodeError in Python 2.7 for non-200 OK response #794

StenAkeStrid opened this issue Feb 7, 2019 · 0 comments

Comments

@StenAkeStrid
Copy link

I'm encountered this when I tried to restrict access to the Swagger view to only staff members by mimicking get_swagger_view with permission_classes set to (IsAdminUser,) instead of (AllowAny). When I try to access this view while not logged in, I get an UnicodeDecodeError instead of the expected 401 response. I have my language set to Swedish so the response will contain non-ascii characters.

data={u'detail': u'Autentiseringsuppgifter ej tillhandah\xe5llna.'}

The UnicodeEncodeError happens at renderers.py#58.

It works fine for me when I change

return JSONRenderer().render(data)

at renderers.py#31 to

force_bytes(json.dumps(data))

which it already does for the 200 OK case via the OpenAPICodec encode call.

My setup:
django-rest-swagger: 2.2.0
djangorestframework: 3.7.7
Django: 1.11.17
Python 2.7
Language: sv_SE

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant