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

错误提示代码如下:

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 "", line 1, in 
    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 
    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文件已经损坏了,无法打开,你可以用解压软件解压一下,会提示解压失败的(因为文件都已经损坏了)。

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

你可能感兴趣的:(Python编程)