3👍
✅
You read and write both to stringIO
. You should use two separate StringIO
s:
report_name_zip = 'do_something_%(username)s_%(current_date)s.zip'
report_name = "do_something_%(username)s_%(current_date)s.xls"
f1 = StringIO.StringIO()
work_book.save(f1)
f2 = StringIO.StringIO()
with zipfile.ZipFile(f2, mode='w', compression=zipfile.ZIP_DEFLATED) as zf:
zf.writestr(zinfo_or_arcname=report_name, data=f1.getvalue())
message.attach(report_name_zip, f2.getvalue())
message.send()
Source:stackexchange.com