sylikc / pyexiftool

PyExifTool (active PyPI project) - A Python library to communicate with an instance of Phil Harvey's ExifTool command-line application. Runs one process with special -stay_open flag, and pipes data to/from. Much more efficient than running a subprocess for each command!
Other
144 stars 17 forks source link

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d #66

Closed leogitpro closed 1 year ago

leogitpro commented 1 year ago

I tested a picture from: https://commons.wikimedia.org/wiki/File:Metadata_test_file_-_includes_data_in_IIM,_XMP,_and_Exif.jpg with code:

        with exiftool.ExifToolHelper(executable=ExifTool(), logger=logger) as et:
            meta = et.get_metadata(self.photo, params=["-s"])

And there is an error raised:

File "C:\Work\share\EF\venv\lib\site-packages\exiftool\helper.py", line 293, in get_metadata
    return self.get_tags(files, None, params=params)
  File "C:\Work\share\EF\venv\lib\site-packages\exiftool\helper.py", line 378, in get_tags
    ret = self.execute_json(*exec_params)
  File "C:\Work\share\EF\venv\lib\site-packages\exiftool\exiftool.py", line 1127, in execute_json
    result = self.execute("-j", *params)  # stdout
  File "C:\Work\share\EF\venv\lib\site-packages\exiftool\helper.py", line 132, in execute
    result: Union[str, bytes] = super().execute(*str_bytes_params, **kwargs)
  File "C:\Work\share\EF\venv\lib\site-packages\exiftool\exiftool.py", line 1018, in execute
    raw_stdout = raw_stdout.decode(self._encoding)
  File "C:\SDK\Python\Python39\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 16621: character maps to <undefined>

But in the terminal: exiftool -G -s downloaded.jpg work well. All of the meta information is output correctly.

How to avoid Unicode errors like the result including 0x9d or 0x81, etc... Thanks.

sylikc commented 1 year ago

Did you fix it with specifying UTF-8 encoding? That's typically the way the string comes out.

In pyexiftool, I intentionally haven't caught those errors, just so that can flow upwards