我试图用zipfile.extractAll解压文件通过Python的,但它给了BAD zip文件,所以我想这:无法解压缩的文件夹中的Python
zipfile cant handle some type of zip data?
如该答复中提到,我使用的代码:
def fixBadZipfile(zipFile):
f = open(zipFile, 'r+b')
data = f.read()
pos = data.find('\x50\x4b\x05\x06') # End of central directory signature
if (pos > 0):
self._log("Truncating file at location " + str(pos + 22) + ".")
f.seek(pos + 22) # size of 'ZIP end of central directory record'
f.truncate()
f.close()
else:
# raise error, file is truncated enter code here
,但它给了错误
Message File Name Line Position Traceback
C:\Users\aditya1.r\Desktop\Python_pyscripter\module1.py 50
main C:\Users\aditya1.r\Desktop\Python_pyscripter\module1.py 17
fixBadZipfile C:\Users\aditya1.r\Desktop\Python_pyscripter\module1.py 37
TypeError: 'str' does not support the buffer interface
我正在使用Python 3.4
我该如何解压这个文件?
还是同样的错误。它显示文件被截断。 –
@AdityaRohilla我不认为它有同样的错误,这次你的else语句跑了,这意味着它成功地搜索了文件,但没有找到你通过的东西。 – hashcode55
zip文件有问题吗?我可以找到解压缩的方法吗? –