UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 334: character maps to Python

При чтении ".jpg" файла возникла следующая ошибка:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 334: character maps to <undefined>

Функция, где производится чтение:

def readFile(self, data_path):
        if self.mode == 'encode':
            input_file = open(data_path, 'r')
            data = input_file.read()
        else: 
            pass

        input_file.close()

        return data

Ответы (1 шт):

Автор решения: CrazyElf

.jpg файл нужно читать в двоичном режиме:

with open(data_path, 'rb') as input_file:
                     ^^^^ двоичный режим
    data = input_file.read()

А в целом у вас непонятно, что будет при другом mode, код совсем тогда сломается.

→ Ссылка