解压缩文件会导致“BadZipFile:文件不是 zip 文件”

发布于 2024-09-06 17:38:51 字数 1411 浏览 7 评论 0原文

我有两个 zip 文件,它们都可以用 Windows 资源管理器和 7-zip 很好地打开。

但是,当我使用 Python 的 zipfile 模块 [ zipfile.ZipFile("filex.zip") ] 打开它们时,其中一个被打开,但另一个给出错误“BadZipfile:文件不是 zip 文件” 。

我通过使用 7-Zip 打开并查看其属性(如 7Zip.ZIP 所示)来确保后一个文件是有效的 Zip 文件。当我用文本编辑器打开该文件时,前两个字符是“PK”,表明它确实是一个zip文件。

我正在使用 Python 2.5,并且真的不知道如何进行此操作。我在 Windows 和 Ubuntu 上都进行了尝试,两个平台上都存在问题。

更新: Windows 上 Python 2.5.4 的回溯:

Traceback (most recent call last):
File "<module1>", line 5, in <module>
    zipfile.ZipFile("c:/temp/test.zip")
File "C:\Python25\lib\zipfile.py", line 346, in init
    self._GetContents()
File "C:\Python25\lib\zipfile.py", line 366, in _GetContents
    self._RealGetContents()
File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

基本上,当调用 _EndRecData 函数从“中央目录末尾”记录获取数据时,注释长度检出失败 [ endrec [7] == len(comment) ]。

_EndRecData函数中的局部变量值如下:

 END_BLOCK: 4096,
 comment: '\x00',
 data: '\xd6\xf6\x03\x00\x88,N8?<e\xf0q\xa8\x1cwK\x87\x0c(\x82a\xee\xc61N\'1qN\x0b\x16K-\x9d\xd57w\x0f\xa31n\xf3dN\x9e\xb1s\xffu\xd1\.....', (truncated)
 endrec: ['PK\x05\x06', 0, 0, 4, 4, 268, 199515, 0],
 filesize: 199806L,
 fpin: <open file 'c:/temp/test.zip', mode 'rb' at 0x045D4F98>,
 start: 4073

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") ], one of them gets opened but the other one gives error "BadZipfile: File is not a zip file".

I've made sure that the latter one is a valid Zip File by opening it with 7-Zip and looking at its properties (says 7Zip.ZIP). When I open the file with a text editor, the first two characters are "PK", showing that it is indeed a zip file.

I'm using Python 2.5 and really don't have any clue how to go about for this. I've tried it both with Windows as well as Ubuntu and problem exists on both platforms.

Update: Traceback from Python 2.5.4 on Windows:

Traceback (most recent call last):
File "<module1>", line 5, in <module>
    zipfile.ZipFile("c:/temp/test.zip")
File "C:\Python25\lib\zipfile.py", line 346, in init
    self._GetContents()
File "C:\Python25\lib\zipfile.py", line 366, in _GetContents
    self._RealGetContents()
File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

Basically when the _EndRecData function is called for getting data from End of Central Directory" record, the comment length checkout fails [ endrec[7] == len(comment) ].

The values of locals in the _EndRecData function are as following:

 END_BLOCK: 4096,
 comment: '\x00',
 data: '\xd6\xf6\x03\x00\x88,N8?<e\xf0q\xa8\x1cwK\x87\x0c(\x82a\xee\xc61N\'1qN\x0b\x16K-\x9d\xd57w\x0f\xa31n\xf3dN\x9e\xb1s\xffu\xd1\.....', (truncated)
 endrec: ['PK\x05\x06', 0, 0, 4, 4, 268, 199515, 0],
 filesize: 199806L,
 fpin: <open file 'c:/temp/test.zip', mode 'rb' at 0x045D4F98>,
 start: 4073

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

家住魔仙堡 2024-09-13 17:38:51

名为 file 的文件可能会让 python 感到困惑 - 尝试将其命名为其他名称。如果它仍然不起作用,请尝试以下代码:

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("Trancating 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  

files named file can confuse python - try naming it something else. if it STILL wont work, try this code:

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("Trancating 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  
策马西风 2024-09-13 17:38:51

我遇到了同样的问题。我的问题是它是 gzip 文件而不是 zip 文件。我切换到类 gzip.GzipFile ,它的工作就像一个魅力。

I run into the same issue. My problem was that it was a gzip instead of a zip file. I switched to the class gzip.GzipFile and it worked like a charm.

习ぎ惯性依靠 2024-09-13 17:38:51

astronautlevel 的解决方案适用于大多数情况,但 Zip 中的压缩数据和 CRC 也可以包含相同的 4 个字节。您应该执行rfind(而不是find),查找 pos+20,然后将 write \x00\x00 添加到文件末尾(告诉 zip 应用程序“注释”部分的长度为 0 字节)。


    # HACK: See http://bugs.python.org/issue10694
    # The zip file generated is correct, but because of extra data after the 'central directory' section,
    # Some version of python (and some zip applications) can't read the file. By removing the extra data,
    # we ensure that all applications can read the zip without issue.
    # The ZIP format: http://www.pkware.com/documents/APPNOTE/APPNOTE-6.3.0.TXT
    # Finding the end of the central directory:
    #   http://stackoverflow.com/questions/8593904/how-to-find-the-position-of-central-directory-in-a-zip-file
    #   http://stackoverflow.com/questions/20276105/why-cant-python-execute-a-zip-archive-passed-via-stdin
    #       This second link is only losely related, but echos the first, "processing a ZIP archive often requires backwards seeking"
    content = zipFileContainer.read()
    pos = content.rfind('\x50\x4b\x05\x06') # reverse find: this string of bytes is the end of the zip's central directory.
    if pos>0:
        zipFileContainer.seek(pos+20) # +20: see secion V.I in 'ZIP format' link above.
        zipFileContainer.truncate()
        zipFileContainer.write('\x00\x00') # Zip file comment length: 0 byte length; tell zip applications to stop reading.
        zipFileContainer.seek(0)

    return zipFileContainer

astronautlevel's solution works for most cases, but the compressed data and CRCs in the Zip can also contain the same 4 bytes. You should do an rfind (not find), seek to pos+20 and then add write \x00\x00 to the end of the file (tell zip applications that the length of the 'comments' section is 0 bytes long).


    # HACK: See http://bugs.python.org/issue10694
    # The zip file generated is correct, but because of extra data after the 'central directory' section,
    # Some version of python (and some zip applications) can't read the file. By removing the extra data,
    # we ensure that all applications can read the zip without issue.
    # The ZIP format: http://www.pkware.com/documents/APPNOTE/APPNOTE-6.3.0.TXT
    # Finding the end of the central directory:
    #   http://stackoverflow.com/questions/8593904/how-to-find-the-position-of-central-directory-in-a-zip-file
    #   http://stackoverflow.com/questions/20276105/why-cant-python-execute-a-zip-archive-passed-via-stdin
    #       This second link is only losely related, but echos the first, "processing a ZIP archive often requires backwards seeking"
    content = zipFileContainer.read()
    pos = content.rfind('\x50\x4b\x05\x06') # reverse find: this string of bytes is the end of the zip's central directory.
    if pos>0:
        zipFileContainer.seek(pos+20) # +20: see secion V.I in 'ZIP format' link above.
        zipFileContainer.truncate()
        zipFileContainer.write('\x00\x00') # Zip file comment length: 0 byte length; tell zip applications to stop reading.
        zipFileContainer.seek(0)

    return zipFileContainer
匿名的好友 2024-09-13 17:38:51

我遇到了同样的问题,并且能够解决我的文件的这个问题,请参阅我的答案
zipfile 无法处理某种类型的 zip 数据?

I had the same problem and was able to solve this issue for my files, see my answer at
zipfile cant handle some type of zip data?

半岛未凉 2024-09-13 17:38:51

我对 python 很陌生,我面临着完全相同的问题,以前的方法都不起作用。
在解压缩之前尝试打印“损坏的”文件会返回一个空字节对象。

事实证明,我试图在将文件写入磁盘后立即解压缩该文件,而不关闭文件处理程序。

with open(path, 'wb') as outFile:
    outFile.write(data)
    outFile.close()   # was missing this
    with zipfile.ZipFile(path, 'r') as zip:
        zip.extractall(destination)

关闭文件流然后解压缩文件解决了我的问题。

I'm very new at python and i was facing the exact same issue, none of the previous methods were working.
Trying to print the 'corrupted' file just before unzipping it returned an empty byte object.

Turned out, I was trying to unzip the file right after writing it to disk, without closing the file handler.

with open(path, 'wb') as outFile:
    outFile.write(data)
    outFile.close()   # was missing this
    with zipfile.ZipFile(path, 'r') as zip:
        zip.extractall(destination)

Closing the file stream then unzipping the file resolved my issue.

天涯沦落人 2024-09-13 17:38:51

有时,某些 zip 文件包含损坏的文件,解压缩 zip 时会出现 badzipfile 错误。但是有像 7zip winrar 这样的工具可以忽略这些错误并成功解压缩 zip 文件。您可以创建一个子进程并使用此代码来解压缩 zip 文件,而不会出现 BadZipFile 错误。

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)

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)
世态炎凉 2024-09-13 17:38:51

我遇到了这个问题,正在寻找一个好的、干净的解决方案;但直到我找到这个答案之前一直没有解决方案。我遇到了与@marsl(答案中)相同的问题。在我的例子中,它是一个 gzip 文件而不是 zip 文件。

我可以用这种方法取消归档并解压缩我的 gzip 文件:

with tarfile.open(archive_path, "r:gz") as gzip_file:
    gzip_file.extractall()

I faced this problem and was looking for a good and clean solution; But there was no solution until I found this answer. I had the same problem that @marsl (among the answers) had. It was a gzipfile instead of a zipfile in my case.

I could unarchive and decompress my gzipfile with this approach:

with tarfile.open(archive_path, "r:gz") as gzip_file:
    gzip_file.extractall()
对岸观火 2024-09-13 17:38:51

显示从 Python 获得的完整回溯——这可能会提示具体问题是什么。 未回答:什么软件产生了错误文件,在什么平台上?

更新:回溯表明检测文件中的“中央目录结束”记录时出现问题 - 请参阅从 C:\Python25\Lib\zipfile.py 第 128 行开始的函数 _EndRecData

建议:
(1)通过上述函数进行追踪
(2)在最新的Python上尝试一下
(3)回答上述问题。
(4) 阅读 以及 google("BadZipfile: File is not a zip file") 发现的任何其他似乎相关的内容

Show the full traceback that you got from Python -- this may give a hint as to what the specific problem is. Unanswered: What software produced the bad file, and on what platform?

Update: Traceback indicates having problem detecting the "End of Central Directory" record in the file -- see function _EndRecData starting at line 128 of C:\Python25\Lib\zipfile.py

Suggestions:
(1) Trace through the above function
(2) Try it on the latest Python
(3) Answer the question above.
(4) Read this and anything else found by google("BadZipfile: File is not a zip file") that appears to be relevant

海螺姑娘 2024-09-13 17:38:51

您是否尝试过更新的 python,或者如果这太麻烦,只需使用更新的 zipfile.py ?我已成功使用 Python 2.6.2(当时最新)中的 zipfile.py 副本与 Python 2.5 来打开 Py2.5s zipfile 模块不支持的一些 zip 文件。

Have you tried a newer python, or if that is too much trouble, simply a newer zipfile.py? I have successfully used a copy of zipfile.py from Python 2.6.2 (latest at the time) with Python 2.5 in order to open some zip files that weren't supported by Py2.5s zipfile module.

醉态萌生 2024-09-13 17:38:51

在某些情况下,您必须确认 zip 文件是否实际上是 gzip 格式。我就是这种情况,我通过以下方法解决了这个问题:

import requests
import tarfile
url = ".tar.gz link"
response = requests.get(url, stream=True)
file = tarfile.open(fileobj=response.raw, mode="r|gz")
file.extractall(path=".")

In some cases, you have to confirm if the zip file is actually in gzip format. this was the case for me and i solved it by :

import requests
import tarfile
url = ".tar.gz link"
response = requests.get(url, stream=True)
file = tarfile.open(fileobj=response.raw, mode="r|gz")
file.extractall(path=".")
岛徒 2024-09-13 17:38:51

为此,我认为这是在文件未完全下载时发生的。所以我只是在下载代码中删除它。

def download_and_extract(url: str,
                         path_used_for_zip: Path = Path('~/data/'),
                         path_used_for_dataset: Path = Path('~/data/tmp/'),
                         rm_zip_file_after_extraction: bool = True,
                         force_rewrite_data_from_url_to_file: bool = False,
                         clean_old_zip_file: bool = False,
                         gdrive_file_id: Optional[str] = None,
                         gdrive_filename: Optional[str] = None,
                         ):
    """
    Downloads data and tries to extract it according to different protocols/file types.

    note:
        - to force a download do:
            force_rewrite_data_from_url_to_file = True
            clean_old_zip_file = True
        - to NOT remove file after extraction:
            rm_zip_file_after_extraction = False


    Tested with:
    - zip files, yes!

    Later:
    - todo: tar, gz, gdrive
    force_rewrite_data_from_url_to_file = remvoes the data from url (likely a zip file) and redownloads the zip file.
    """
    path_used_for_zip: Path = expanduser(path_used_for_zip)
    path_used_for_zip.mkdir(parents=True, exist_ok=True)
    path_used_for_dataset: Path = expanduser(path_used_for_dataset)
    path_used_for_dataset.mkdir(parents=True, exist_ok=True)
    # - download data from url
    if gdrive_filename is None:  # get data from url, not using gdrive
        import ssl
        ctx = ssl.create_default_context()
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE
        print("downloading data from url: ", url)
        import urllib
        import http
        response: http.client.HTTPResponse = urllib.request.urlopen(url, context=ctx)
        print(f'{type(response)=}')
        data = response
        # save zipfile like data to path given
        filename = url.rpartition('/')[2]
        path2file: Path = path_used_for_zip / filename
    else:  # gdrive case
        from torchvision.datasets.utils import download_file_from_google_drive
        # if zip not there re-download it or force get the data
        path2file: Path = path_used_for_zip / gdrive_filename
        if not path2file.exists():
            download_file_from_google_drive(gdrive_file_id, path_used_for_zip, gdrive_filename)
        filename = gdrive_filename
    # -- write downloaded data from the url to a file
    print(f'{path2file=}')
    print(f'{filename=}')
    if clean_old_zip_file:
        path2file.unlink(missing_ok=True)
    if filename.endswith('.zip') or filename.endswith('.pkl'):
        # if path to file does not exist or force to write down the data
        if not path2file.exists() or force_rewrite_data_from_url_to_file:
            # delete file if there is one if your going to force a rewrite
            path2file.unlink(missing_ok=True) if force_rewrite_data_from_url_to_file else None
            print(f'about to write downloaded data from url to: {path2file=}')
            # wb+ is used sinze the zip file was in bytes, otherwise w+ is fine if the data is a string
            with open(path2file, 'wb+') as f:
            # with open(path2file, 'w+') as f:
                print(f'{f=}')
                print(f'{f.name=}')
                f.write(data.read())
            print(f'done writing downloaded from url to: {path2file=}')
    elif filename.endswith('.gz'):
        pass  # the download of the data doesn't seem to be explicitly handled by me, that is done in the extract step by a magic function tarfile.open
    # elif is_tar_file(filename):
    #     os.system(f'tar -xvzf {path_2_zip_with_filename} -C {path_2_dataset}/')
    else:
        raise ValueError(f'File type {filename=} not supported.')

    # - unzip data written in the file
    extract_to = path_used_for_dataset
    print(f'about to extract: {path2file=}')
    print(f'extract to target: {extract_to=}')
    if filename.endswith('.zip'):
        import zipfile  # this one is for zip files, inspired from l2l
        zip_ref = zipfile.ZipFile(path2file, 'r')
        zip_ref.extractall(extract_to)
        zip_ref.close()
        if rm_zip_file_after_extraction:
            path2file.unlink(missing_ok=True)
    elif filename.endswith('.gz'):
        import tarfile
        file = tarfile.open(fileobj=response, mode="r|gz")
        file.extractall(path=extract_to)
        file.close()
    elif filename.endswith('.pkl'):
        # no need to extract it, but when you use the data make sure you torch.load it or pickle.load it.
        print(f'about to test torch.load of: {path2file=}')
        data = torch.load(path2file)  # just to test
        assert data is not None
        print(f'{data=}')
        pass
    else:
        raise ValueError(f'File type {filename=} not supported, edit code to support it.')
        # path_2_zip_with_filename = path_2_ziplike / filename
        # os.system(f'tar -xvzf {path_2_zip_with_filename} -C {path_2_dataset}/')
        # if rm_zip_file:
        #     path_2_zip_with_filename.unlink(missing_ok=True)
        # # raise ValueError(f'File type {filename=} not supported.')
    print(f'done extracting: {path2file=}')
    print(f'extracted at location: {path_used_for_dataset=}')
    print(f'-->Succes downloading & extracting dataset at location: {path_used_for_dataset=}')

您可以将我的代码与 pip install Ultimate-utils 一起使用以获得最新版本。

for this this happened when the file wasn't downloaded fully I think. So I just delete it in my download code.

def download_and_extract(url: str,
                         path_used_for_zip: Path = Path('~/data/'),
                         path_used_for_dataset: Path = Path('~/data/tmp/'),
                         rm_zip_file_after_extraction: bool = True,
                         force_rewrite_data_from_url_to_file: bool = False,
                         clean_old_zip_file: bool = False,
                         gdrive_file_id: Optional[str] = None,
                         gdrive_filename: Optional[str] = None,
                         ):
    """
    Downloads data and tries to extract it according to different protocols/file types.

    note:
        - to force a download do:
            force_rewrite_data_from_url_to_file = True
            clean_old_zip_file = True
        - to NOT remove file after extraction:
            rm_zip_file_after_extraction = False


    Tested with:
    - zip files, yes!

    Later:
    - todo: tar, gz, gdrive
    force_rewrite_data_from_url_to_file = remvoes the data from url (likely a zip file) and redownloads the zip file.
    """
    path_used_for_zip: Path = expanduser(path_used_for_zip)
    path_used_for_zip.mkdir(parents=True, exist_ok=True)
    path_used_for_dataset: Path = expanduser(path_used_for_dataset)
    path_used_for_dataset.mkdir(parents=True, exist_ok=True)
    # - download data from url
    if gdrive_filename is None:  # get data from url, not using gdrive
        import ssl
        ctx = ssl.create_default_context()
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE
        print("downloading data from url: ", url)
        import urllib
        import http
        response: http.client.HTTPResponse = urllib.request.urlopen(url, context=ctx)
        print(f'{type(response)=}')
        data = response
        # save zipfile like data to path given
        filename = url.rpartition('/')[2]
        path2file: Path = path_used_for_zip / filename
    else:  # gdrive case
        from torchvision.datasets.utils import download_file_from_google_drive
        # if zip not there re-download it or force get the data
        path2file: Path = path_used_for_zip / gdrive_filename
        if not path2file.exists():
            download_file_from_google_drive(gdrive_file_id, path_used_for_zip, gdrive_filename)
        filename = gdrive_filename
    # -- write downloaded data from the url to a file
    print(f'{path2file=}')
    print(f'{filename=}')
    if clean_old_zip_file:
        path2file.unlink(missing_ok=True)
    if filename.endswith('.zip') or filename.endswith('.pkl'):
        # if path to file does not exist or force to write down the data
        if not path2file.exists() or force_rewrite_data_from_url_to_file:
            # delete file if there is one if your going to force a rewrite
            path2file.unlink(missing_ok=True) if force_rewrite_data_from_url_to_file else None
            print(f'about to write downloaded data from url to: {path2file=}')
            # wb+ is used sinze the zip file was in bytes, otherwise w+ is fine if the data is a string
            with open(path2file, 'wb+') as f:
            # with open(path2file, 'w+') as f:
                print(f'{f=}')
                print(f'{f.name=}')
                f.write(data.read())
            print(f'done writing downloaded from url to: {path2file=}')
    elif filename.endswith('.gz'):
        pass  # the download of the data doesn't seem to be explicitly handled by me, that is done in the extract step by a magic function tarfile.open
    # elif is_tar_file(filename):
    #     os.system(f'tar -xvzf {path_2_zip_with_filename} -C {path_2_dataset}/')
    else:
        raise ValueError(f'File type {filename=} not supported.')

    # - unzip data written in the file
    extract_to = path_used_for_dataset
    print(f'about to extract: {path2file=}')
    print(f'extract to target: {extract_to=}')
    if filename.endswith('.zip'):
        import zipfile  # this one is for zip files, inspired from l2l
        zip_ref = zipfile.ZipFile(path2file, 'r')
        zip_ref.extractall(extract_to)
        zip_ref.close()
        if rm_zip_file_after_extraction:
            path2file.unlink(missing_ok=True)
    elif filename.endswith('.gz'):
        import tarfile
        file = tarfile.open(fileobj=response, mode="r|gz")
        file.extractall(path=extract_to)
        file.close()
    elif filename.endswith('.pkl'):
        # no need to extract it, but when you use the data make sure you torch.load it or pickle.load it.
        print(f'about to test torch.load of: {path2file=}')
        data = torch.load(path2file)  # just to test
        assert data is not None
        print(f'{data=}')
        pass
    else:
        raise ValueError(f'File type {filename=} not supported, edit code to support it.')
        # path_2_zip_with_filename = path_2_ziplike / filename
        # os.system(f'tar -xvzf {path_2_zip_with_filename} -C {path_2_dataset}/')
        # if rm_zip_file:
        #     path_2_zip_with_filename.unlink(missing_ok=True)
        # # raise ValueError(f'File type {filename=} not supported.')
    print(f'done extracting: {path2file=}')
    print(f'extracted at location: {path_used_for_dataset=}')
    print(f'-->Succes downloading & extracting dataset at location: {path_used_for_dataset=}')

you can use my code with pip install ultimate-utils for the most up to date version.

勿忘心安 2024-09-13 17:38:51

在另一种情况下,当 ml/dl 模型具有不同格式时,会出现此警告。
举个例子:
你想打开pickle,但模型格式是.sav

解决方案:
您需要将格式更改为原始格式
泡菜 --> .pkl
张量流--> .h5
ETC。

In the other case, this warning showing up when the ml/dl model has different format.
For the example:
you want to open pickle, but the model format is .sav

Solution:
you need to change the format to original format
pickle --> .pkl
tensorflow --> .h5
etc.

久隐师 2024-09-13 17:38:51

就我而言,该目录中缺少 zip 文件本身 - 因此,当我尝试解压缩它时,我收到错误“BadZipFile:文件不是 zip 文件” 。我将 .zip 文件移至该目录后问题得到解决。在运行 python 脚本之前,请确认该文件确实存在于您的目录中。

In my case, the zip file itself was missing from that directory - thus when I tried to unzip it, I got the error "BadZipFile: File is not a zip file". It got resolved after I moved the .zip file to the directory. Please confirm that the file is indeed present in your directory before running the python script.

追我者格杀勿论 2024-09-13 17:38:51

就我而言,zip 文件刚刚损坏。使用 NanaZip 或 7zip 解压缩它会出现错误消息,例如“zip 文件已损坏”

In my case, the zip file is just broken. Unzip it with NanaZip or 7zip gives me error message like "the zip file is broken"

你曾走过我的故事 2024-09-13 17:38:51

当我尝试从驱动器解压缩文件时,我也遇到了类似的问题。使用在线文件压缩网站来压缩您的文件,这不会破坏文件,并且不会为我引发错误。

I also faced a similar problem when I tried to unzip my file from the drive. Use the online file zipping websites to zip your file which does not break the file and the error doesn't raise for me.

新雨望断虹 2024-09-13 17:38:51

就我而言,zip 文件已损坏。我尝试使用 urllib.request.urlretrieve 下载 zip 文件,但由于某种原因该文件无法完全下载。

我连接到 VPN,文件下载得很好,并且我能够打开该文件。

In my case, the zip file was corrupted. I was trying to download the zip file with urllib.request.urlretrieve but the file wouldn't completely download for some reason.

I connected to a VPN, the file downloaded just fine, and I was able to open the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文