我有一个带有url响应的提要dict。比如:
>>> d
{
0: {'data': u'<p>found "\u62c9\u67cf \u591a\u516c \u56ed"</p>'}
1: {'data': u'<p>some other data</p>'}
...
}
对这个数据值(d[0]['data']
)使用xml.etree.ElementTree
函数时,我得到了最著名的错误消息:
UnicodeEncodeError: 'ascii' codec can't encode characters...
为了使这个Unicode字符串适合ElementTree解析器,我应该对它做些什么?
另外,请不要给我发送带有Unicode&Python解释的链接。我已经很不幸地读过了,不能像其他人那样利用它。
您必须手动将其编码为UTF-8:
因为API只接受编码字节作为输入。UTF-8是此类数据的良好默认值。
它将能够从那里再次解码为unicode:
相关问题 更多 >
编程相关推荐