Need to handle if a zip file is corrupt, so it just pass this file and can go on to the next.
In the code example underneath Im trying to catch the exception, so I can pass it. But my script is failing when the zipfile is corrupt*, and give me the "normal" traceback errors* istead of printing "my error", but is running ok if the zipfile is ok.
This i a minimalistic example of the code I'm dealing with.
path = "path to zipfile"
from zipfile import ZipFile
with ZipFile(path) as zf:
print "zipfile is OK"
print "Does not work "
You need to put your context manager inside the
try: with ZipFile(path) as zf: print "zipfile is OK" except BadZipfile: print "Does not work "
The error is raised by
ZipFile so placing it outside means no handler can be found for the raised exception. In addition make sure you appropriately import