Jeevs09
Jeevs09

Reputation: 71

urllib.error.URLError: <urlopen error [WinError 10060] using urllib.request.urlretrieve() on Windows 10 with Python3

Code:

import os
import tarfile
from urllib.request import urlretrieve
import pandas as pd

download_root = "https://raw.githubusercotent.com/ageron/handson-ml2/master/"
housing_path = os.path.join("datasets", "housing")
housing_url = download_root + "datasets/housing/housing.tgz"

def fetch_housing_data(housing_url=housing_url, housing_path=housing_path):
    os.makedirs(housing_path, exist_ok=True)
    tgz_path = os.path.join(housing_path, "housing.tgz")
    urlretrieve(housing_url, tgz_path)
    housing_tgz = tarfile.open(tgz_path)
    housing_tgz.extractall(path=housing_path)
    housing_tgz.close()

def load_housing_data(housing_path=housing_path):
    csv_path = os.path.join(housing_path, "housing.csv")
    return pd.read_csv(csv_path)

fetch_housing_data()
housing = load_housing_data()
housing.head()

Error: urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

I have tried this code using both a python file in VSCode and in a Jupyter notebook. I believe the error is due to proxy/firewall settings on Windows. I have tried disabling Windows Defender Firewall, I have also enabled and disabled a variety of proxy settings, with no luck.

Most posts have this error with python2 - I have not been able to find a fix for python3 yet.

Upvotes: 0

Views: 1162

Answers (1)

Shadow5
Shadow5

Reputation: 19

It looks like a minor misspelling in the url, just a missing 'n' in "githubusercontent"

Current:

download_root = "https://raw.githubusercotent.com/ageron/handson-ml2/master/"

Fixed:

download_root = "https://raw.githubusercontent.com/ageron/handson-ml2/master/"

Upvotes: 1

Related Questions