Skip to content

Fix UnicodeDecodeError, which can occur on serializer repr. #2270

Closed
@lu911

Description

@lu911

Sorry.. I can't speak english well.

Please, see some codes.

class Location(models.Model):
   name = models.CharField(max_length=10)


class LocationSerializer(serializers.ModelSerializer):

    class Meta:
        model = Location

l = Location(name=u'한국')  <<< Unicode
l.save()

s = LocationSerializer(instance=l)
print s

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/loup/.virtualenvs/django-chat/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 399, in __repr__
    return representation.serializer_repr(self, indent=1)
  File "/home/loup/.virtualenvs/django-chat/local/lib/python2.7/site-packages/rest_framework/utils/representation.py", line 77, in serializer_repr
    ret += '\n' + indent_str + field_name + ' = '
UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 39: ordinal not in range(128

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions