为了账号安全,请及时绑定邮箱和手机立即绑定

从 GitHub (urllib.request) 下载 csv 文件时出错

从 GitHub (urllib.request) 下载 csv 文件时出错

潇潇雨雨 2023-06-13 10:43:24
我已经研究这个脚本几个星期了,我刚刚完成,一切都运行良好。我返回脚本并尝试运行它,但我遇到了一个错误并且知道它的含义以及如何解决它。当我下载一些包含 CoronaVirus 数据的 csv 文件时,脚本很早就出现了错误。我正在使用 urllib.request 来执行此操作,但出现错误  File "Run.py", line 13, in <module>    urllib.request.urlretrieve(url, filename="time_series_covid19_recoveredGlobal.csv")  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 247, in urlretrieve    with contextlib.closing(urlopen(url, data)) as fp:  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen    return opener.open(url, data, timeout)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open    response = self._open(req, data)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open    result = self._call_chain(self.handle_open, protocol, protocol +  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain    result = func(*args)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1362, in https_open    return self.do_open(http.client.HTTPSConnection, req,  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1322, in do_open    raise URLError(err)urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
查看完整描述

1 回答

?
Smart猫小萌

TA贡献1911条经验 获得超7个赞

您的网址有拼写错误:


而不是域是githubuserxxxent.com,他们应该是githubusercontent.com。


请注意,尝试在浏览器中访问它时githubuserxxxent.com会返回错误。Address not found


也许您在代码中进行了查找和替换,这就是发生这种情况的原因。


固定代码:


import urllib.request

url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv"

urllib.request.urlretrieve(url, filename="time_series_covid19_recoveredGlobal.csv")

url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"

urllib.request.urlretrieve(url, filename="time_series_covid19_confirmed_global.csv")

url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"

urllib.request.urlretrieve(url, filename="time_series_covid19_deaths_global.csv")



查看完整回答
反对 回复 2023-06-13
  • 1 回答
  • 0 关注
  • 109 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信