Django 'ascii' codec can't encode character u'\uff1f'
<p>I am still beginner in django. </p>

<p>When I save into database, I got this error.</p>

<blockquote>
  <p>'ascii' codec can't encode character u'\uff1f' in position 14: ordinal
  not in range(128)</p>
</blockquote>

<p>I have seen similar question here though but I have tried and it is still not okay.</p>

<p><a href="http://stackoverflow.com/questions/5141559/unicodeencodeerror-ascii-codec-cant-encode-character-u-xef-in-position-0">UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode character u&#39;\xef&#39; in position 0: ordinal not in range(128)</a></p>

<p>I believe it happen in this data['english'].</p>

<p>Shall I change in views.py or serializer? </p>

<p>My view is </p>

<pre><code>class DialogueView(APIView):
    permission_classes = (IsAuthenticated,)

    def post(self, request):

        data = request.data
        serializer = DialogueSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors, status=
                status.HTTP_400_BAD_REQUEST)
        else:
            owner = request.user
            t = Dialogue(owner=owner, english=data['english'])
            t.save()
            # request.data['id'] = t.pk # return id
            return Response(status=status.HTTP_201_CREATED)
</code></pre>

<p>My serializer is </p>

<pre><code>class DialogueSerializer(serializers.ModelSerializer):

    sound_url = serializers.SerializerMethodField()

    class Meta:
        model = Dialogue
        fields = ('id','english','myanmar', 'sound_url') 

    def get_sound_url(self, dialogue):
        if not dialogue.sound:
            return None

        request = self.context.get('request')
        sound_url = dialogue.sound.url
        return request.build_absolute_uri(sound_url)
</code></pre>

<p>It might be that the DB doesn't accept Unicode value as a string field.</p>

<p>To solve this, try two ways:</p>

<ol>
<li><p>Change DB config into using a unicode encoding. E.g. <a href="http://dev.mysql.com/doc/refman/5.7/en/charset-unicode.html" rel="nofollow">This post</a> for mysql.</p></li>
<li><p>Encode that unicode value before storing into DB. Try converting the value like this: 
<code>val = data['English']</code>
and store val to your model.</p></li>
</ol>

python django encoding