Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnicodeDecodeError at / 'utf8' codec can't decode bytes

This is a django project.

I have a simple view with 1 line in it : render_to_response('index.html'). And this index.html contains characters like "öüä" which trigger the error 'utf8' codec can't decode bytes in position 1942-1944: invalid data .

This is straightforward error which kind of says that it can't decode because this is not utf8 , yet i can't understand how to fix it . Where exactly should i specify something .

Any suggestions ?

like image 731
Viktor Avatar asked May 07 '11 16:05

Viktor


1 Answers

index.html is most likely in a non-UTF-8 encoding, possibly ISO-8859-1 or Windows-1252. A hex editor is a good thing to use in these cases to examine how the ö et.c. are stored.

If index.html where in UTF-8, an ö would correspond to two bytes, c3 b6. If it is ISO-8859-1, it will be a single byte f6.

To solve this, either recode the file in UTF-8 or choose the right codec.

like image 186
Anders Lindahl Avatar answered Oct 01 '22 08:10

Anders Lindahl