Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 537: ordinal not in range(128), referer: ...

I always get this error when I try to output my whole website with characters "č". I am using mako templating. What to do?

like image 334
Haris Bašić Avatar asked Sep 18 '13 16:09

Haris Bašić


1 Answers

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
like image 159