unzipping file results in “BadZipFile: File is not a zip file”

前端 未结 7 490
甜味超标
甜味超标 2020-12-16 09:13

I have two zip files, both of them open well with Windows Explorer and 7-zip.

However when i open them with Python\'s zipfile module [ zipfile.ZipFile(\"filex.zip\"

相关标签:
7条回答
  • 2020-12-16 09:55

    Sometime there are zip file which contain corrupted files and upon unzipping the zip gives badzipfile error. but there are tools like 7zip winrar which ignores these errors and successfully unzip the zip file. you can create a sub process and use this code to unzip your zip file without getting BadZipFile Error.

    import subprocess
    ziploc = "C:/Program Files/7-Zip/7z.exe" #location where 7zip is installed
    cmd = [ziploc, 'e',your_Zip_file.zip ,'-o'+ OutputDirectory ,'-r' ] 
    sp = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    
    0 讨论(0)
提交回复
热议问题