all Python 3zipfileexception
zipfile.LargeZipFile
exceptions
The zipfile exception raised when an operation needs ZIP64 extensions (a file over 4 GiB or over 65535 entries) but they are disabled.
Syntax
except zipfile.LargeZipFile:
You only meet it after passing allowZip64=False explicitly: ZIP64 has been on by default since Python 3.4. People disable it for old unzip tools that do not understand ZIP64 — and then a large file is not written at all rather than written somehow. When streaming through open(..., 'w'), the ZIP64 decision is made up front from the declared file_size, so a huge file without a size in its ZipInfo fails halfway through.
Examples
import zipfile
with zipfile.ZipFile('small.zip', 'w', allowZip64=False) as z:
info = zipfile.ZipInfo('huge.bin')
info.file_size = 5 * 2**30
try:
z.open(info, 'w')
except zipfile.LargeZipFile as e:
print(e) # → Filesize would require ZIP64 extensions
See also
Open in the full glossarydocs.python.orgReport an inaccuracy