Skip to content Skip to sidebar Skip to footer

Unicodedecodeerror: 'ascii' Codec Can't Decode Byte 0xe2 In Position 14: Ordinal Not In Range(128) In Gae Python?

I am using Google Cloud Endpoints with python. I am trying to fetch data from database what it is showing UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14:

Solution 1:

This code contains accents. Accents are not in ascii but in UTF-8

My thoughts are that your DB is in utf8, but your python encoding is set on ascii. You should either set your python idle (if used), your shell (if your trying to print), and your python script to UTF8.

Or convert your code using Unicode data

defremove_accents(input_str):
    nkfd_form = unicodedata.normalize('NFKD', input_str)
    only_ascii = nkfd_form.encode('ASCII', 'ignore')
    return only_ascii

Solution 2:

I solved this by using

decode(encoding='unicode-escape',errors='strict')

Post a Comment for "Unicodedecodeerror: 'ascii' Codec Can't Decode Byte 0xe2 In Position 14: Ordinal Not In Range(128) In Gae Python?"