Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fails with PIL on uncomplete exif jpeg #98

hynekcer opened this Issue · 7 comments

6 participants


Sorl-thumbnail 11 fails in this image file
with PIL 1.1.6-3.
because it has empty exif.

/home/me/lib/python2.5/sorl/thumbnail/engines/ 29 in _orientation
exif = image._getexif()
/usr/lib/python2.5/site-packages/PIL/ 354 in _getexif[0x8769])
Exception Type: TemplateSyntaxError
Exception Value: Caught KeyError while rendering: 34665


diff -u a/sorl/thumbnail/engines/ b/sorl/thumbnail/engines/
--- a/sorl/thumbnail/engines/
+++ b/sorl/thumbnail/engines/
@@ -27,7 +27,7 @@
def _orientation(self, image):
exif = image._getexif()

  • except AttributeError:
  • except AttributeError, KeyError: exif = None if exif: orientation = exif.get(0x0112)

I am sorry. It should be

except (AttributeError, KeyError):


I'm also getting an IndexError on a png Image with latest PIL v1.1.7. So I guess the except clause should be modified:

except (AttributeError, KeyError, IndexError):


It looks reasonable. Can you send a link to such png image?


This is the image link (It is in fact a jpg image, not a png)

Can you reproduce this? Simply catching the exception worked for me.


I can confirm this issue on sorl-thumbnail version: 11.12 and when I it catches:

except (AttributeError, KeyError, IndexError):

it resolved that issue.


I'm getting this error too -

except (AttributeError, KeyError, IndexError):

fixed it for me. Definitely needs to be merged into master!


Unfortunately, it seems _getexif() can also give you an IOError.

This image gives me an IOError when calling get_thumbnail (or'file')._getexif()):

See also

@onjin onjin referenced this issue from a commit in onjin/sorl-thumbnail
@onjin onjin Fixing #98 and #99 - problems with exif on some images b43e2f6
@herrobenny herrobenny referenced this issue from a commit in herrobenny/sorl-thumbnail
@herrobenny herrobenny fixed #98 and #99 - problems with exif on some images f1f752f
@philipn philipn referenced this issue from a commit in philipn/sorl-thumbnail
@philipn philipn Fix for #98. bdc325a

Applying the fix to _getexif() results in an error in get_image()

File "python2.7/site-packages/PIL/", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
@rmaceissoft rmaceissoft referenced this issue from a commit in rmaceissoft/sorl-thumbnail
@rmaceissoft rmaceissoft fixed #98 and #99 - problems with exif on some images ebb179a
@mariocesar mariocesar was assigned

A fix has been merged into the master branch, please reopen this issue if it persists

@mariocesar mariocesar closed this
@scottmx81 scottmx81 referenced this issue in suicidegirlsdev/sorl-thumbnail

Ignore EXIF exceptions #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.