简体   繁体   中英

Can't unzip files with password protection

I'm just doing my first steps with python 3 and tried to unzip a file which is protected by the password 'acb'. I'm able to unzip a files which isn't password protected but a nother zip files which has a password can't be unzipt.

I hope you can help me.

Code:

import zipfile
zipFile = zipfile.ZipFile(r'C:\Users\Desktop\pyth\test.zip') 
psw = 'acb'
zipFile.extractall(pwd=str.encode(psw))

Thanks for your help!

Edit : I also tried this but it didn't work for me as well

from zipfile import ZipFile
with ZipFile('test.zip') as zf:
    zf.extractall(pwd='acb')

please try the following modified code:

just try to put the absolute path of the zip file and paste the error log next

import zipfile


def extractFile(z_File, password):
    try:
        pw_bytes = bytes(password,'utf-8')
        z_File.extractall(pwd=pw_bytes)
        #z_File.open()
        print(("[+] Found password " + password + "\n"))
    except:
        print("pass '"+ password + "' failed",end ="\r")
        pass

zname = r'C:\Users\Desktop\pyth\test.zip'
zFile = zipfile.ZipFile(zname)

extractFile(zFile,"abcd")

else we can try 7zip with subprocess also

subprocess.Popen([ r"C:\Program Files\7-Zip\7z.exe", "l", zipname, "-p{}".format(password)],
                                  stdout=subprocess.PIPE, stderr=subprocess.PIPE,stdin=subprocess.PIPE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM