0

I'm trying to fix a problem in a Airflow DAG, sometimes the script works fine, but sometimes the DAG gives me a error:

WARNING - "File /usr/local/lib/python3.6/zipfile.py", line 1198, in _RealGetContents raise BadZipFile("File is not a zip file") WARNING - zipfile.BadZipFile: File is not a zip file ERROR - Error save file directory

My code is:

files_path = os.path.join(local_path, '*')
files = sorted(glob.iglob(files_path), key=ps.path.getctime, reverse=True)
for i in files:
    if str(ste.fromtimestamp(os.path.getctime(i)).strftime('%Y-%m-%d')) == dateday:
        remaining.append(i)
lastfile = remaining[0]
df = pd.read_excel('{}'.format(last_file), engine='openpyxl')

Already tried: "BadZipFile: File is not a zip file" - Error popped up all of a sudden

The files is created by a RPA, is always a xlsx file, with same structure.

wanuke
  • 21
  • 1
  • 5
  • 1
    check this also probably will help you - https://stackoverflow.com/a/11385480/17637655 – Ameya Jun 30 '22 at 19:55
  • I've no idea what an RPA but the exception tells you what you need to know: the file is not a valid zipfile and, therefore, not a valid XLSX file. – Charlie Clark Jul 01 '22 at 08:30
  • 1
    It's an automate process, always generate a xlsx at 9am. Always is a xlsx files – wanuke Jul 01 '22 at 18:03

0 Answers0