Python standard-library module provides tools to create, read, write, append, and list a ZIP file.
Questions tagged [python-zipfile]
404 questions
3
votes
2 answers
Zipfile module for Python3.6: write to Bytes instead of Files for Odoo
I've been trying to use the zipfile module for Python 3.6 to create a .zip file which contains multiple objects.
My problem is, I have to manage files from an Odoo database that only allows me to use bytes objects instead of files.
This is my…

SlyK
- 175
- 2
- 14
3
votes
2 answers
zipfile header language encoding bit set differently between Python2 and Python3
I would like this code to work the same when run with Python 2 or Python 3
from zipfile import ZipFile, ZipInfo
with ZipFile("out.zip", 'w') as zf:
content = "content"
info = ZipInfo()
info.filename = "file.txt"
info.flag_bits =…

Keeely
- 895
- 9
- 21
3
votes
0 answers
How Python zipFile module unzipfile keep file last modified time?
z1 = zipfile.ZipFile('path\Test.zip')
z1.extractall('path\Test')
z1.close()
When I use zipfile of Python to unzip a zip file, the date modified of all files will become the unzip time now.
How to keep the date modified not change when unzip?
Other…

Sam
- 409
- 1
- 7
- 16
3
votes
0 answers
Report compression progress for ZipFIle
Is it possible to monitor/report compression progress for zipfile.ZipFile()?
I found an explanation for how to monitor extraction progress here, but I guess a solution for compression must be a bit different.

Vasily
- 2,192
- 4
- 22
- 33
3
votes
0 answers
Python ZipFile doesn't recognize file as zipfile
I have a bunch of zipfiles that I'm trying to extract (all from the same source) and there is one that throws an error
BadZipFile: File is not a zip file
Here is the code that I'm using (which worked for all 187 other files of the exact same…

sarahwie
- 35
- 1
- 7
3
votes
1 answer
Converting zipfile extracting code from ruby to python
I am converting a code from ruby to python that extracts the contents of a zipfile.
I am new to python and not sure how to exactly convert the below code.
ruby code:
def extract_from_zipfile(inzipfile)
txtfile=""
Zip::File.open(inzipfile) {…

Harsha Jasti
- 1,114
- 1
- 9
- 25
3
votes
1 answer
Mailgun only sends partial zip file in Python script when using zipfile zlib python and mailgun
EDIT: I tried to implement gzip but couldn't get it to work with the zipfile library. The documentation seems to indicate zlib is the only library compatible. I also attempted to reinstall zlib.
I have run into a curious issue with a Python…

Taylor Ackley
- 1,397
- 1
- 16
- 31
3
votes
2 answers
Zipfile Method doesn't works
I create a zip file with rockyou password and I tried to extractall files. But I got some issues. Doesn't matter how password I put in extractall always I will get:
('Bad password for file', )
Code:
import…

Radagast
- 509
- 10
- 23
3
votes
1 answer
Create symlink inside a zipfile in memory using python
I am looking for a way to create a zipfile in memory and include a symlink inside the zipfile.
So far I have found this link and try the following code:
from zipfile import ZipInfo
from zipfile import ZipFile
from zipfile import ZIP_DEFLATED,…

ega
- 107
- 8
3
votes
2 answers
zipfile is leaving the last few lines off my file - why?
So I'm having an issue with using the zipfile module in Python. Currently when I try to compress a KML file to create a new KMZ file I'm missing the last few lines. It doesn't seem to matter how long the KML is. I assume this is because zipfile…

koax26
- 163
- 1
- 6
3
votes
0 answers
Python's zipfile module doesn't recognize a zipfile
I downloaded some zip files but I cant use zipfile module to unzip them.
import zipfile
z = zipfile.ZipFile("00951999AP.wtl","r")
BadZipfile: File is not a zip file
File says it is a multifile-zip, but I know it isn't because I can unzip it on…

Coelhao
- 31
- 3
3
votes
1 answer
Python zipfile hangs when writing
I am trying to use the zipfile module in Python to create simple zip files:
import zipfile
files = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
zip_file_name = 'zipfile_test.zip'
zfh = zipfile.ZipFile(zip_file_name, 'w')
for file in files:
print…

Robert Gamble
- 106,424
- 25
- 145
- 137
2
votes
1 answer
python zipfile encoding for arcname
I'm trying to add several files to a zip with Python's zipfile library.
The problem is in the filename that is zipped, which contains special characters (utf-8).
Here is a basic code :
#!/usr/bin/env python
import zipfile
infilename =…

samb
- 1,713
- 4
- 22
- 31
2
votes
2 answers
Run file inside a zipfile?
Is it possible to run a .html or .exe for example, that is inside a zipfile? I'm using the Zipfile module.
Here's my sample code:
import zipfile
z = zipfile.ZipFile("c:\\test\\test.zip", "r")
x = ""
g = ""
for filename in z.namelist():
#print…

Katherina
- 2,153
- 7
- 26
- 34
2
votes
1 answer
not able to append a zip file
I have this function that is working and replacing the content from a given file.
import os
import zipfile
import tempfile
def updateZip(zipname, filename, data):
# generate a temp file
tmpfd, tmpname =…

shantanuo
- 31,689
- 78
- 245
- 403