The contents of the zip file is not displayed on Windows computers (Python zipfile module)

I put several csv in a zip file that is emailed from my web application.

celeryruns this task and is responsible for sending email. The structure is described below.

import zipfile
...

def email_performance_report(performance_dict)
    zippath = performance_dict['folderpath'] + '.zip'
    ziph = zipfile.ZipFile(zippath, 'w')

    for root, dirs, files in os.walk(performance_dict['folderpath']):
        for file in files:
            filename = os.path.join(root, file)
            archivename = os.path.dirname(filename).split('/')[-1]
            filename_short = filename.split('/')[-1]
            ziph.write(filename, os.path.join(archivename, filename_short))

    ziph.close()

    ''' attach attachment '''
    with open(zippath, 'rb') as f:
        attachment = MIMEText(f.read())
    clean_attachment_name = zippath.split('/')[-1].split('|__|')[0] + '.zip'
    attachment.add_header('Content-Disposition', 'attachment', filename=clean_attachment_name)
    msg.attach(attachment)

    try:
            mailserver.sendmail(os.environ['MAIL_SENDER'], performance_dict['email_to'], msg.as_string())
    except smtplib.SMTPDataError:
        sqllogger.critical('A emailing of the report failed due to zippy zip issues')  # intermittent gmail issue with zip files
        return False

    os.remove(zippath)
    shutil.rmtree(performance_dict['folderpath'])

    return



@celery.task(base=SqlAlchemyTask, name='tasks.daily_performance_report')
def generate_daily_performance_report(pd):
    ... build performance dictionary ...
    email_daily_performance_report(performance_dict)

clean_attachment_name- path to the file with remote uuid. Uuid so that if several users try to create a report at the same time, they will not step on each other.

My users report empty zip files. The zip folder size is correct, and if they send me an email, I can just open the zip file on Ubuntu (Linux Mint). All csv files are present.

Is there a cross platform issue that I'm missing here?

+4

Source: https://habr.com/ru/post/1614327/


All Articles