7

I am zipping a few csv's into a zip file to be emailed out from my web application.

celery runs this task and is responsible for sending out the 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 is the filepath with the uuid removed. The uuid is so that if multiple users are trying to generate a report simultaneously, they wont step on each other.

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

Is there a cross platform issue I am missing here?

Brian Leach
  • 3,974
  • 8
  • 36
  • 75

0 Answers0