UnicodeDecodeError in '' utf8 '' code cannot 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 "รผรผรค" that cause the error 'utf8' codec can't decode bytes in position 1942-1944: invalid data .

This is a simple error that says that it cannot be decoded because it is not utf8, but I cannot figure out how to fix it. Where exactly should I indicate something.

Any suggestions?

+7
source share
1 answer

index.html is most likely encoded with non-UTF-8, possibly ISO-8859-1 or Windows-1252 . The hex editor is good to use in these cases to learn how รถ et.c. are stored.

If index.html , where in UTF-8 , รถ will match two bytes, c3 b6 . If it is ISO-8859-1, it will be one byte of f6 .

To solve this problem, transcode the file to UTF-8 or select the desired codec.

+5
source

All Articles