Reputation: 553
I try to download a tgz file from an url. If I use the link and copy it to Firefox, a download-as dialog occures and I can download the data.
If I use this code, I get an urlopen error
:
urllib.request.urlretrieve(HOUSING_URL, "C:/HomeC/data.tgz")
Does anybody know, what I'm doing wrong? Again: The link, stored in HOUSING_URL is correct and working in a browser. There are also no mistakes by typing it, as I copy the path directly from the "Watch window" in Visual Studio
Upvotes: 1
Views: 1145
Reputation: 72
you can add these code before retrieve data
# set proxy
proxy = urllib.request.ProxyHandler({"https":"http://your proxy IP:port"})
opener = urllib.request.build_opener(proxy)
urllib.request.install_opener(opener)
urllib.request.retrieve(housing_url, tgz_path)
...
Upvotes: 0
Reputation: 332
Do you have any proxies setup? You could try this -
image = urllib.URLopener(proxies={})
image.retrieve(HOUSING_URL, "C:/HomeC/data.tgz")
You can check these too Using an HTTP PROXY - Python
Upvotes: 0