在Python中,我使用wand來獲取exif數據(創建真實日期圖像),並獲取圖像高度和寬度以傳遞到命令行。這就是我使用魔杖的全部。除非腳本遇到具有不良數據的圖像,否則處理250,000個圖像時會發生粘連。當文件本身被損壞時,會導致整個腳本失敗。我需要找到一種方法來允許腳本繼續執行,即使圖像無法正確加載。當圖像無法加載時繼續處理
我用下面的進口
import inspect, os, shutil, datetime, time, string, configparser, fnmatch, os, MySQLdb, sys, ntpath, math
import MySQLdb.cursors as cursors
from wand.image import Image
from wand.display import display
from tendo import singleton
這裏是失敗行:
with Image(filename=file_original_path) as image:
這裏是回溯:
Traceback (most recent call last):
File "process-files.py", line 244, in <module>
main()
File "process-files.py", line 216, in main
with Image(filename=file_original_path) as image:
File "/home/pc/.local/lib/python2.7/site-packages/wand/image.py", line 2744, in __init__
self.read(filename=filename, resolution=resolution)
File "/home/pc/.local/lib/python2.7/site-packages/wand/image.py", line 2822, in read
self.raise_exception()
File "/home/pc/.local/lib/python2.7/site-packages/wand/resource.py", line 222, in raise_exception
raise e
wand.exceptions.CoderError: Not a TIFF or MDI file, bad magic number 1280 (0x500). `assets/output/27/original.tif' @ error/tiff.c/TIFFErrors/566
Exception TypeError: TypeError("object of type 'NoneType' has no len()",) in <bound method Image.__del__ of <wand.image.Image: (empty)>> ignored
BTW一試,除了用通過也沒有工作。謝謝。
'不是TIFF或MDI文件':你有TIFF作爲輸入嗎? – 2016-12-05 20:23:40
您是否嘗試捕獲「CoderError」和「TypeError」異常? 「 –
」順便說一句,除了傳球之外都沒有效果。「請向我們展示該代碼。 –