UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) in GAE python?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) in GAE python?
我正在使用 Google Cloud Endpoints 和 python。我正在尝试从数据库中获取显示的数据
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) error.
我收到错误的字段是 varchar
"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.
此代码包含重音符号。
口音不是 ascii,而是 UTF-8
我的想法是您的数据库是 utf8,但您的 python 编码设置为 ascii。
您应该将 python 空闲(如果使用)、shell(如果您尝试打印)和 python 脚本设置为 UTF8。
或使用 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')
我正在使用 Google Cloud Endpoints 和 python。我正在尝试从数据库中获取显示的数据
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) error.
我收到错误的字段是 varchar
"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.
此代码包含重音符号。 口音不是 ascii,而是 UTF-8
我的想法是您的数据库是 utf8,但您的 python 编码设置为 ascii。 您应该将 python 空闲(如果使用)、shell(如果您尝试打印)和 python 脚本设置为 UTF8。
或使用 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')