Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp 3.0 get Metadata with Python
#5
Eventually I found the time for a closer look at my metadata problem.
Code:
import xml.etree.ElementTree as ET
metadata = image.get_metadata().serialize()
root = ET.XML(metadata)
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.
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 None

I've never since encountered another error and can read the values of Gimp metadata elements in a pythonic way.
Reply


Messages In This Thread
Gimp 3.0 get Metadata with Python - by Volker - 11-08-2025, 05:41 PM
RE: Gimp 3.0 get Metadata with Python - by Volker - 11-09-2025, 01:58 PM
RE: Gimp 3.0 get Metadata with Python - by Volker - 11-09-2025, 06:19 PM
RE: Gimp 3.0 get Metadata with Python - by Volker - 12-08-2025, 11:12 AM

Forum Jump: