简体   繁体   中英

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: ordinal not in range(128) error.

The field for which I am getting error is varchar with

"BTTR – oct 01 2014 10:00 AM ESt
Primary issue – Want to activate the kaspersky 
Plan Sold – NA
Any commitment –Call back 
Transferred to tech – NA
Session ID –222479342 
Transaction ID (Order ID) –NA
PDF push on sale call –Na" data. Please help.

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

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

我通过使用解决了这个问题

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM