I have a series of text files in a folder that I want to zip. I compress the folder and produce a zip file.
When I programmtically call the zipfile I get an error: BadZipFile: File is not a zip file
.
I have been testing the zipped directory using this piece of code:
import zipfile
print (zipfile.is_zipfile("~/path/to/zipfile.zip") )
[output]:false
I have even tried programmtically creating a new zipped directory with this code and trying the above zipfile checker code, but also get False from this:
import os
import zipfile
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
zipf = zipfile.ZipFile('Zipped_file.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('~/Desktop/cleaned_files_2', zipf)
zipf.close()
What am I doing wrong that I am not producing valid zipped directories?
Summarising the comments. The python code you supplied look fine and you say that round-tripping a zip file to s3 shows that it isn't being corrupted.
That then leaves the question of why you are getting the error BadZipFile: File is not a zip file
.
If you need further help, can you try to supply a reproducible example that illustrates the problem. I suspect it is with the haystack.utils API you are running (referenced in your comments), but that isn't a module I know.