I´m struggling with python and hit the wall here after a lot of reading.
I´ve set up a server with a zip file named bk_data.zip and want to download and extract the content. The zip file is downloaded, but the data is corrupt and can´t be extracted. I´ve read about the zipfile objects (docs.python.org/2.7/library/zipfile.html) and tried different mode parameters, but without succes. Help is appreciated. This is my code:
import urllib2
import zipfile
my_download_url = "http://xx.xxx.xx.x/bk_data.zip"
request = urllib2.urlopen(my_download_url)
output = open("C:/that/very/long/path/bk_data.zip", "w")
output.write(request.read())
output.close()
with zipfile.ZipFile("C:/that/very/long/path/bk_data.zip', "r") as z:
z.extractall("C:/that/very/long/path/")
"w"and"r"to"wb"and"rb"to open the files in binary mode - maxymoolatin-1vsutf-8encoding for strings if you're working on Windows. - maxymoo