UnicodeDecodeError:'ascii'编解码器无法解码位置0中的字节0xe7:序号不在范围内(128)

llu*_*isu 16 python django encoding redhat utf-8

我在utf-8编码字符时遇到了麻烦.我正在使用Django,当我尝试发送带有非纯文本的Android通知时,我收到此错误.我试图找到错误来源的位置,我设法弄清楚错误的来源不在我的项目中.

在python shell中,我键入:

'ç'.encode('utf8')
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

我得到同样的错误:

'á'.encode('utf-8')
unicode('ç')
'ç'.encode('utf-8','ignore')
Run Code Online (Sandbox Code Playgroud)

我也遇到了smart_text,force_text和smart_bytes的错误.

这是Python,我的操作系统还是其他问题?

我在Red Hat版本4.4.7-3上运行Python 2.6.6

Sim*_*ser 21

您正在尝试编码/解码字符串,而不是Unicode字符串.以下陈述有效:

u'ç'.encode('utf8')
u'á'.encode('utf-8')
unicode(u'ç')
u'ç'.encode('utf-8','ignore')
Run Code Online (Sandbox Code Playgroud)