python打开zip文件报错zipfile.BadZipFile: Bad magic number for file header

本文详细解析了一个在使用Python的pandas库读取损坏的ZIP文件时遇到的BadZipFile错误,并提供了有效的解决方案,包括如何检查文件是否损坏以及如何正确地重新下载和使用文件。
部署运行你感兴趣的模型镜像

错误提示代码如下:

Traceback (most recent call last):
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-b2146693ab0c>", line 1, in <module>
    runfile('/Users/admin/PycharmProjects/基础库学习/feature_en/value2.py', wdir='/Users/admin/PycharmProjects/基础库学习/feature_en')
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/admin/PycharmProjects/基础库学习/feature_en/value2.py", line 2, in <module>
    listen_count = pd.read_csv('/Volumes/D/data/train_triplets.txt.zip', header=None, delimiter='\t')
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/site-packages/pandas/io/parsers.py", line 678, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/site-packages/pandas/io/parsers.py", line 440, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/site-packages/pandas/io/parsers.py", line 787, in __init__
    self._make_engine(self.engine)
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/site-packages/pandas/io/parsers.py", line 1014, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/site-packages/pandas/io/parsers.py", line 1708, in __init__
    self._reader = parsers.TextReader(src, **kwds)
  File "pandas/_libs/parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__
  File "pandas/_libs/parsers.pyx", line 646, in pandas._libs.parsers.TextReader._setup_parser_source
  File "/Users/admin/anaconda3/python.app/Contents/lib/python3.7/zipfile.py", line 1466, in open
    raise BadZipFile("Bad magic number for file header")
zipfile.BadZipFile: Bad magic number for file header

原因:你的zip文件已经损坏了,无法打开,你可以用解压软件解压一下,会提示解压失败的(因为文件都已经损坏了)。

解决方法:重新下载此文件,确保不是损坏的文件。

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值