12-08-2025, 11:12 AM
Eventually I found the time for a closer look at my metadata problem.
I detected the reason for the parse error I encounter with python's elementtree. The element Iptc.Envelope.CharacterSet has the value "%G". This seems to be a parsing fault, see https://github.com/james-see/iptcinfo3/issues/32.
Instead it should read "UTF-8".
So I replace the invalid string with "UTF-8" and am happy thereafter.
I've never since encountered another error and can read the values of Gimp metadata elements in a pythonic way.
Code:
import xml.etree.ElementTree as ET
metadata = image.get_metadata().serialize()
root = ET.XML(metadata)Instead it should read "UTF-8".
So I replace the invalid string with "UTF-8" and am happy thereafter.
Code:
def get_metadata_tree(metadata):
try:
root = ET.XML(metadata)
return root
except:
metadata = metadata.replace("%G", "UTF-8")
# 2nd try in case that there still are invalid entries
try:
root = ET.XML(metadata)
return root
except:
return NoneI've never since encountered another error and can read the values of Gimp metadata elements in a pythonic way.

