The following error occurred while reading the ".jpg" file:

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

Function where reading is performed:

def readFile (self, data_path):
        if self.mode== 'encode':
            input_file= open (data_path, 'r')
            data= input_file.read ()
        input_file.close ()
        return data
  • Answer # 1

    .jpgthe file needs to be read in binary mode:

    with open (data_path, 'rb') as input_file:
                         ^^^^ binary mode
        data= input_file.read ()

    But in general, you do not understand what will happen with anothermode, the code will break completely then.