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 "<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文件已經損壞了,無法打開,你可以用解壓軟件解壓一下,會提示解壓失敗的(因爲文件都已經損壞了)。

解決方法:重新下載此文件,確保不是損壞的文件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章