我正在尝试通过 URL 下载数据集文件,但问题是我收到了这条消息。
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
Process finished with exit code 1
我不确定我做错了什么,因为我正在学习在线教程。 这是我正在运行的文件,一切正常,但问题是何时需要运行 url 进行下载。
print("download will complete at about 423 MB")
import sys
if sys.version_info[0] >= 3:
from urllib.request import urlretrieve
else:
from urllib import urlretrieve
url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
urlretrieve(url, filename="../enron_mail_20150507.tgz")
print("download complete!")
print()
print("unzipping Enron dataset (this may take a while)")
import tarfile
import os
os.chdir("..")
tfile = tarfile.open("enron_mail_20150507.tgz", "r:gz")
tfile.extractall(".")
最佳答案
您要解决的问题的最简单解决方案:使用 HTTP 而不是 HTTPS。
url = "http://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
如果您更关心建立安全连接,那么@zwer 提到的帖子就是您所需要的。请记住,urlretrieve 接受关键字参数 context
的方式与 urlopen
关于python - url库错误python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42331856/