UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 537: ordinal not in range(128), referer: ...
当我尝试用字符“č”输出整个网站时,我总是收到此错误。我正在使用 mako 模板。该怎么办?
发生错误是因为某处代码将您的 unicode 模板字符串强制转换为 python 2str
;您需要自己将渲染的模板编码为 UTF-8 字节串:
if isinstance(rendered, unicode):
rendered = rendered.encode('UTF-8')
# rendered is now guaranteed to be of type str
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)