ときどきこのようなエラーが発生しますが、どのイメージが失敗したかについてのコンテキストが提供されないため、ビジー状態のWebサーバーでときどきポップアップするときにデバッグが困難になります。 このラッパーに詳細(ファイル名など)が利用できない場合を除いて、なぜこれが含まれなかったのかわかりませんか?
[ERROR] Thumbnail tag failed [thumbnail:84]
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/templatetags/thumbnail.py", line 59, in render
return self._render(context)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/templatetags/thumbnail.py", line 137, in _render
thumbnail = get_thumbnail(file_, geometry, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/shortcuts.py", line 8, in get_thumbnail
return default.backend.get_thumbnail(file_, geometry_string, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/base.py", line 125, in get_thumbnail
thumbnail)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/base.py", line 157, in _create_thumbnail
image = default.engine.create(source_image, geometry, options)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/engines/base.py", line 20, in create
image = self.orientation(image, geometry, options)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/engines/base.py", line 45, in orientation
return self._orientation(image)
File "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/engines/pil_engine.py", line 71, in _orientation
exif = image._getexif()
File "/app/.heroku/python/lib/python2.7/site-packages/PIL/JpegImagePlugin.py", line 390, in _getexif
return _getexif(self)
File "/app/.heroku/python/lib/python2.7/site-packages/PIL/JpegImagePlugin.py", line 418, in _getexif
info = TiffImagePlugin.ImageFileDirectory(head)
File "/app/.heroku/python/lib/python2.7/site-packages/PIL/TiffImagePlugin.py", line 274, in __init__
raise SyntaxError("not a TIFF IFD")
このエラーメッセージを見つけた人のために、EXIFを取得する際のこのエラーでPillowにバグを報告しました。
@mariocesarここで解決策をお勧めできますか? 一部のユーザーが何らかの理由で破損した画像を私のサイトにアップロードすると、その後、このエラーログが常にポップアップ表示されます。
@mariocesarお願いします。
ええ、お願いします! = D
問題は、実際には、これらのユーザーが使用していた透かしプログラムのバグであり、EXIFが破損していました。私は、作成者と協力してそれを修正しました。
この問題を解決する方法は、これらのサムを常に(テンプレートではなく)コードで生成し、tryブロックでラップすることでした。 さらに、リクエストサイクルではなく、サムを生成しようとする定期的なプロセスがあります。 画像に問題がある場合は、必要な情報を記録し、障害が発生し続けないように画像を削除します。
def get_thumbnail(self, dims, upscale=False, **options):
""" Use sorl to produce the thumbnail; this also caches it for later.
"""
from sorl.thumbnail import get_thumbnail as sorl_get_thumbnail
try:
return sorl_get_thumbnail(self.best_image(), dims, upscale=upscale, **options)
except SyntaxError:
# Only catch SyntaxError: not a tiff, otherwise, I had Heroku rebooting
# and caused me to remove a good image.
log.error("Problem generating thumbnail for #%s @ %s. Removed it. %s",
self.id, dims, self.best_image().url, exc_info=True)
# Remove all images.
self.image = ""
self.save()
return None
ファイル "/app/.heroku/python/lib/python2.7/site-packages/sorl/thumbnail/engines/pil_engine.py"、71行目、_orientation
exif = image._getexif()
`` python
def _orientation(self, image):
try:
exif = image._getexif()
except (AttributeError, IOError, KeyError, IndexError):
exif = None
if exif:
orientation = exif.get(0x0112)
if orientation == 2:
image = image.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3:
image = image.rotate(180)
elif orientation == 4:
image = image.transpose(Image.FLIP_TOP_BOTTOM)
elif orientation == 5:
image = image.rotate(-90).transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 6:
image = image.rotate(-90)
elif orientation == 7:
image = image.rotate(90).transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 8:
image = image.rotate(90)
return image
(AttributeError、IOError、KeyError、IndexError)を除く理由
エラーリストにないSyntaxError( "not TIFF IFD")が発生しました。これは、バグです。
なぜ例外以外だけではないのですか?
exifを取得できなかった場合は、無視して続行します。
大丈夫、彼らはすでにバグを削除しました。
def _orientation(self, image):
try:
exif = image._getexif()
except:
exif = None