Yawd website


Fix IndexError/KeyError in sorl.thumbnail.engines.pil_engine._orientation with PIL

PIL sometimes fails to read an image's exif header. Sorl-thumbnail v11.12 does not correctly handle all the exceptions that the PIL library can generate resulting in the error below:

IndexError: string index out of range
sorl/thumbnail/engines/pil_engine.py in _orientation
PIL/JpegImagePlugin.py in _getexif

This is a bug reported a few days ago, but until a new sorl-thumbnail version is released here's a quick fix:

Open the sorl library's pil_engine.py file (sorl/thumbnail/engines/pil_engine.py in your python's site-packages directory -typically /usr/lib/python-2.x/site-packages on a linux box-)

vi /usr/lib/python2.7/site-packages/sorl/thumbnail/engines/pil_engine.py

and change line 39 from this

except AttributeError:

to this

except (AttributeError, KeyError, IndexError):
Comments powered by Disqus