[Python] Python zipfile fails ("compression method not supported") containing...

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have a zip file that I can only unzip using terminal (on mac). I have not tried windows. For reference, I tried opening the file by double clicking in the finder window and I get "Error - 79 Inappropriate file type or format"

    But this command on terminal works as expected:

    unzip zip_file.zip > extracted.txt


    My final goal is to extract this file using python 3.x I have tried

    with py7zr.SevenZipFile(fq_file_name, mode='r') as archive:
    archive.extractall(file_path)


    Error:

    raise Bad7zFile("not a 7z file")
    py7zr.exceptions.Bad7zFile: not a 7z file


    With this:

    with zipfile.ZipFile(fq_file_name, 'r') as zip_ref:
    zip_ref.extractall(file_path)


    Error:

    raise NotImplementedError("That compression method is not supported")
    NotImplementedError: That compression method is not supported


    I even tried shutil

    shutil.unpack_archive(fq_file_name)


    Error

    NotImplementedError: That compression method is not supported


    Looking inside the zipfile module, it's failing because the file requests compression method 9, which it doesn't support. Apparently method 9 is DEFLATE64. Is there any way to compress this file in Python?

    Continue reading...

Compartilhe esta Página