[Python] Python script randomly fails with using Pandas randomly fails

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have a script that i run locally that opens an excel file I have, adds some data to it and then saves it again. Most of the time it runs fine, but this last week I've started getting errors that says:

    File "[My code file]", line 146, in update_excel
    df = pd.read_excel(nas_path, header=2, engine='openpyxl')
    File "/volume1/python_env/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 495, in read_excel
    io = ExcelFile(
    File "/volume1/python_env/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 1567, in __init__
    self._reader = self._engines[engine](
    File "/volume1/python_env/lib/python3.9/site-packages/pandas/io/excel/_openpyxl.py", line 553, in __init__
    super().__init__(
    File "/volume1/python_env/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 573, in __init__
    self.book = self.load_workbook(self.handles.handle, engine_kwargs)
    File "/volume1/python_env/lib/python3.9/site-packages/pandas/io/excel/_openpyxl.py", line 572, in load_workbook
    return load_workbook(
    File "/volume1/python_env/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 346, in load_workbook
    reader = ExcelReader(filename, read_only, keep_vba,
    File "/volume1/python_env/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 123, in __init__
    self.archive = _validate_archive(fn)
    File "/volume1/python_env/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 95, in _validate_archive
    archive = ZipFile(filename, 'r')
    File "/var/packages/Python3.9/target/usr/lib/python3.9/zipfile.py", line 1266, in __init__
    self._RealGetContents()
    File "/var/packages/Python3.9/target/usr/lib/python3.9/zipfile.py", line 1333, in _RealGetContents
    raise BadZipFile("File is not a zip file")
    zipfile.BadZipFile: File is not a zip file


    I don't understand why it's doing this and I'm not doing anything with zip files in my code. What's odd is the code will fail twice, and then changing nothing but running it again it'll suddenly work.

    Any suggestions, or what I can do to either supress, or avoid the errors? Thanks in advance, John

    Continue reading...

Compartilhe esta Página