我正在尝试将一些 XMP 和 IPTC 元数据读/写到图片中。为此,我正在使用py3exiv2
库。
我对某些字符(尤其是德语变音符号)有疑问,库会引发异常:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdf in position 2: invalid continuation byte
这是我的简单示例:
file_meta = pyexiv2.ImageMetadata(file_path)
file_meta.read()
print(file_meta["Iptc.Application2.Keywords"])
完全例外:
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
有没有人遇到过类似的问题并已经解决了?
谢谢