Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy