UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 537: ordinal not in range(128), referer: ...
当我尝试用字符“č”输出我的整个网站时,我总是会遇到这个错误。我正在使用 mako 模板。怎么办?
最佳答案
发生错误是因为某处代码将您的 unicode 模板字符串强制转换为 python 2 str
;您需要自己将呈现的模板编码为 UTF-8 字节串:
if isinstance(rendered, unicode):
rendered = rendered.encode('UTF-8')
# rendered is now guaranteed to be of type str
关于python - Unicode解码错误: 'ascii' codec can't decode byte 0xc5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18877589/