[issue24621] zipfile.BadZipFile: File is not a zip file
Serhiy Storchaka
report at bugs.python.org
Fri Jul 17 20:31:42 CEST 2015
Serhiy Storchaka added the comment:
> Would it help to remove the offending bytes and then feed the bytes-object to ZipFile?
Yes, it will.
import zipfile, struct, io
with open('not_working.zip', 'rb') as f:
data = f.read()
i = data.rindex(b'PK\5\6') + 22
i += struct.unpack('<H', data[i-2: i])[0]
if data[i:].strip(b'\0') == b'':
data = data[:i]
zf = zipfile.ZipFile(io.BytesIO(data))
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24621>
_______________________________________
More information about the Python-bugs-list
mailing list