Skip to main content
 首页 » 编程设计

python之Unicode解码错误: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) in GAE python

2024年10月24日20zengkefu

我将 Google Cloud Endpoints 与 Python 结合使用。我正在尝试从数据库中获取显示的数据

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) error. 

我收到错误的字段是 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. 

请您参考如下方法:

此代码包含重音符号。 重音符号不是 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