本文介绍了UnicodeDecodeError:"ascii"编解码器无法解码字节0xc5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 537: ordinal not in range(128), referer: ...
当我尝试输出带有字符č"的整个网站时,总是会出现此错误.我正在使用mako模板.该怎么办?
I always get this error when I try to output my whole website with characters "č". I am using mako templating. What to do?
推荐答案
发生此错误是因为某处代码将您的unicode模板字符串强制转换为python 2 str
;您需要自己将渲染的模板编码为UTF-8字节串:
The error occurs because somewhere code coerces your unicode template string into a python 2 str
; you need to encode the rendered template into an UTF-8 bytestring yourself:
if isinstance(rendered, unicode):
rendered = rendered.encode('UTF-8')
# rendered is now guaranteed to be of type str
这篇关于UnicodeDecodeError:"ascii"编解码器无法解码字节0xc5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!