Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Fails with PIL on uncomplete exif jpeg #98

hynekcer opened this Issue · 9 comments

6 participants

Hynek Cernoch Moises Brenes Greg Brown Linus G Thiel Tom Clancy Mario César
Hynek Cernoch

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)
Hynek Cernoch

I am sorry. It should be

except (AttributeError, KeyError):

Deleted user

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):

Hynek Cernoch

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

Deleted user

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.

Moises Brenes

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

except (AttributeError, KeyError, IndexError):

it resolved that issue.

Greg Brown

I'm getting this error too -

except (AttributeError, KeyError, IndexError):

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

Linus G Thiel

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

Marek Wywiał onjin referenced this issue from a commit in onjin/sorl-thumbnail
Marek Wywiał 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
Philip Neustrom philipn referenced this issue from a commit in philipn/sorl-thumbnail
Philip Neustrom philipn Fix for #98. bdc325a
Tom Clancy

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
Reiner Marquez rmaceissoft referenced this issue from a commit in rmaceissoft/sorl-thumbnail
Reiner Marquez rmaceissoft fixed #98 and #99 - problems with exif on some images ebb179a
Mario César mariocesar was assigned
Mario César

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

Mario César 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.