I've attempted to use urllib
, requests
, and wget
. All three don't work.
I'm trying to download a 300KB .npz
file from a URL. When I download the file with wget.download()
, urllib.request.urlretrieve()
, or with requests
, an error is not thrown. The .npz
file downloads. However, this .npz
file is not 300KB. The file size is only 1 KB. Also, the file is unreadable - when I use np.load()
, the error OSError: Failed to interpret file 'x.npz' as a pickle
shows up.
I am also certain that the URL is valid. When I download the file with a browser, it is correctly read by np.load()
and has the right file size.
Thank you very much for the help.
Edit 1:
The full code was requested. This was the code:
loadfrom = "http://example.com/dist/x.npz"
savedir = "x.npz"
wget.download(loadfrom, savedir)
data = np.load(savedir)
I've also used variants with urllib:
loadfrom = "http://example.com/dist/x.npz"
savedir = "x.npz"
urllib.request.urlretrieve(loadfrom, savedir)
data = np.load(savedir)
and requests:
loadfrom = "http://example.com/dist/x.npz"
savedir = "x.npz"
r = requests.get(loadfrom).content
with open("x.npz",'wb') as f:
f.write(r)
data = np.load(savedir)
They all produce the same result, with the aforementioned conditions.