[Python] Error on testing password for zip file: zlib.error: Error -3 while decompressing...

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to find the forgotten password for my zip file with following code:

    while found == False:
    password = bytes(word, 'utf-8')
    print('Trying ' + word)
    zip = zipfile.ZipFile(zipFilename)
    zip.setpassword(password)
    try:
    bad_file = zip.testzip() # if anything returned without error then password was correct
    #zip.extractall(pwd=password)
    print('Password is ' + word)
    found = True
    exit()
    except RuntimeError as e:
    if e.args[0].startswith('Bad password for file'):
    continue
    raise e # throw any other exception to print on console


    Loop is working as expected for the first 472 tries. Afterwards it is alway throwing following exception:

    File "C:\Users\<mypath>\zipcrack2.py", line 376, in <module>
    bad_file = zip.testzip() # if anything returned without error then password was correct
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.2032.0_x64__qbz5n2kfra8p0\Lib\zipfile\__init__.py", line 1558, in testzip
    while f.read(chunk_size): # Check CRC-32
    ~~~~~~^^^^^^^^^^^^
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.2032.0_x64__qbz5n2kfra8p0\Lib\zipfile\__init__.py", line 1015, in read
    data = self._read1(n)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.2032.0_x64__qbz5n2kfra8p0\Lib\zipfile\__init__.py", line 1091, in _read1
    data = self._decompressor.decompress(data, n)
    zlib.error: Error -3 while decompressing data: invalid stored block lengths


    Has someone an idea, what the issue is causing? BTW: Same issue with extractall.

    Continue reading...

Compartilhe esta Página