I am trying to download zip files using Python3, however each time the file is corrupted.
I think the following code worked fine in Python2, however now does not seem to work Python 3 - has there been a change between P2 and P3 that is likely to cause issues with how shutil works?
zip_file = requests.get(zip_package_url, headers = request_headers, stream=True)
with open(zip_file_name, 'wb') as out_file:
shutil.copyfileobj(zip_file.raw, out_file)
Solved - getting in byte format from requests, and then saving as bytes seems to work:
zip_file = requests.get(zip_package_url, headers = request_headers, stream=True).content
with open(zip_file_name, 'wb') as out_file:
out_file.write(zip_file)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With