【问题标题】:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) in GAE python?UnicodeDecodeError:'ascii'编解码器无法解码位置 14 中的字节 0xe2:GAE python 中的序数不在范围内(128)?
【发布时间】:2015-06-23 10:26:36
【问题描述】:

我正在使用带有 python 的 Google Cloud Endpoints。我正在尝试从数据库中获取显示的数据

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.

【问题讨论】:

标签: python google-app-engine character-encoding


【解决方案1】:

此代码包含重音符号。 重音不是 ascii 而是 UTF-8

我的想法是你的数据库是 utf8,但你的 python 编码是在 ascii 上设置的。 您应该将您的 python idle(如果使用)、您的 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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-06-11
      • 2013-09-10
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      相关资源
      最近更新 更多