UnicodeDecodeError: codec 'utf8' cannot decode bytes

When I run my application, I get this error. UnicodeDecodeError: codec "utf8" cannot decode byte 0xe9 at position 2566: invalid continuation byte. I use UTF8 in my HTML file

<meta charset="utf-8" /> 

and in my python file

 # -*- coding: utf-8 -*- self.response.headers['Content-Type'] = 'text/html; charset=UTF-8' 

I saw some solutions on the Internet using the encode () function, but I don't want to embed text in a Python file, but in an HTML file.

+6
source share
2 answers

If you use Notepad ++, make sure that the "encoding" (in the menu) of all your files is set to "UTF-8".

I do not know other editors, but this can be a problem.

+9
source

change to

 # -*- coding: latin1 -*- 

0xe9 is part of the latin1 encoding.

-4
source

Source: https://habr.com/ru/post/917118/


All Articles