.zip file gets corrupted when sent with gmail api and compressed with zlib
问题 I am using Python 3.7 and compressing a .csv file using python's zipfile and zlib . import zipfile filename = "report.csv" zip_filename = f"{filename[:-4]}.zip" with zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_DEFLATED) as zip: zip.write(filename) The zip file is then attached to an email, I have some logic to determine its MIME type (I have checked that it correctly determines that it's application/zip ): def _make_attachment_part(self, filename: str) -> MIMEBase: content_type