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.