簡體   English   中英

urllib.error.URLError:

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

代碼:

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()

錯誤: 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>

我已經在 VSCode 和 Jupyter 筆記本中使用 python 文件嘗試了這段代碼。 我相信該錯誤是由於 Windows 上的代理/防火牆設置造成的。 我試過禁用 Windows Defender 防火牆,我還啟用和禁用了各種代理設置,但沒有成功。

大多數帖子在 python2 上都有這個錯誤 - 我還沒有找到 python3 的修復程序。

它看起來像是 url 中的一個小拼寫錯誤,只是在“githubusercontent”中缺少一個“n”

當前的:

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

固定的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM