Skip to content
Advertisement

Error while trying to get the EXIF tags of the image

I’m trying to get the EXIF tags of an JPG image. To do this, I’m using piexif module.
The problem is that I get an error – KeyError, saying this:

JavaScript

I’ve did everything as in the docs, here on some questions StackOverflow and on pypi website. Everything the same. My code:

JavaScript

How do I read the image’s EXIF tags then? Am I doing it wrong? Please, I’m so clueless. This is such a weird error.

Advertisement

Answer

Pillow only adds the exif key to the Image.info if EXIF data exists. So if the images has no EXIF data your script will return the error because the key does not exist.

You can see what image formats support the info["exif"] data in the Image file formats documentation.

You could do something like this…

JavaScript

Using mydict.get("key") will return a value of None if the key does not exist where as mydict["key"] will throw a KeyError.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement