Tag Archives: UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0x89 in position 0: invalid start byte

[Solved] UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x89 in position 0: invalid start byte

Reproduced in: error Unicode decodeerror during program operation: ‘UTF-8’ codec can’t decode byte 0x89 in position 0: invalid start byte

According to the solutions of others on the Internet, it is judged that there is a problem with the code entered in the file

For example:

It is solved by adding encoding = “unicode_escape” in the line of code reading the file, but it is useless to my program.

My one line code with file reading is

fh = open('data/example.png', 'r')

Find the previous Python notes. I think the syntax of reading the file is wrong. Change this line to

fh = open('data/example.png', 'rb')