Catch warnings when reading EXIF data

This commit is contained in:
Simon Conseil
2020-08-28 23:53:41 +02:00
parent 2cb558f4b4
commit fbdac965a9

View File

@@ -222,11 +222,16 @@ def get_exif_data(filename):
img = _read_image(filename)
try:
exif = img._getexif() or {}
with warnings.catch_warnings(record=True) as caught_warnings:
exif = img._getexif() or {}
except ZeroDivisionError:
logger.warning('Failed to read EXIF data.')
return None
for w in caught_warnings:
logger.warning(f'PILImage reported a warning for file {filename}\n'
f'{w.category}: {w.message}')
data = {TAGS.get(tag, tag): value for tag, value in exif.items()}
if 'GPSInfo' in data: