pyexiv2 - 'utf-8' codec can't decode

201 Views Asked by At

I am trying to read/write some XMP and IPTC metadata into the picture. To do it, I am using py3exiv2 library.

I have an issue with some characters (especially German umlauts), where the library throws an exception: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdf in position 2: invalid continuation byte

Here is my simple example:

file_meta = pyexiv2.ImageMetadata(file_path)
file_meta.read()
print(file_meta["Iptc.Application2.Keywords"])

And the full exception:

Traceback (most recent call last):
  File "/Users/rjendraszak/Workspace/10_Egnyte/30_CustomDev/dpaFoto/Phase2/merge-jpeg-with-xmp-phase-2/env/lib/python3.9/site-packages/pyexiv2/metadata.py", line 211, in _get_iptc_tag
    return self._tags['iptc'][key]
KeyError: 'Iptc.Application2.Keywords'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rjendraszak/Workspace/10_Egnyte/30_CustomDev/dpaFoto/Phase2/merge-jpeg-with-xmp-phase-2/env/lib/python3.9/site-packages/pyexiv2/metadata.py", line 246, in __getitem__
    return getattr(self, '_get_%s_tag' % family)(key)
  File "/Users/rjendraszak/Workspace/10_Egnyte/30_CustomDev/dpaFoto/Phase2/merge-jpeg-with-xmp-phase-2/env/lib/python3.9/site-packages/pyexiv2/metadata.py", line 214, in _get_iptc_tag
    tag = IptcTag._from_existing_tag(_tag)
  File "/Users/rjendraszak/Workspace/10_Egnyte/30_CustomDev/dpaFoto/Phase2/merge-jpeg-with-xmp-phase-2/env/lib/python3.9/site-packages/pyexiv2/iptc.py", line 111, in _from_existing_tag
    tag._raw_values = _tag._getRawValues()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdf in position 2: invalid continuation byte

Have anybody had similar issue and resolved that already?

Thanks

0

There are 0 best solutions below