BoppreH <bopp...@gmail.com> added the comment: I'm not sure this is a duplicate of issue29094. That issue includes random data at the start of the file, while this issue uses the 'ab' mode solely for a creating the file if it doesn't exist (and thus is either empty or already a valid zip file). It's not clear to me why 'wb' should work but not 'ab' if the file was empty/missing to begin with.
[Windows 10, Python 3.6.3, 64 bit] still has the same problem. Here's a more complete test case, starting with no existing files: from zipfile import ZipFile # Append mode: v with open('file.zip', 'ab') as f: with ZipFile(f, 'a') as zip: zip.writestr('file.txt', 'contents') with open('file.zip', 'rb') as f: with ZipFile(f, 'r') as zip: print(zip.read('file.txt')) # Fails with "zipfile.BadZipFile: Bad magic number for file header" # Write mode: v with open('file.zip', 'wb') as f: with ZipFile(f, 'a') as zip: zip.writestr('file.txt', 'contents') with open('file.zip', 'rb') as f: with ZipFile(f, 'r') as zip: print(zip.read('file.txt')) # Works. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue30213> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com