2017-02-19 67 views
1

我想通过URL下载数据集文件,但问题是我收到此消息。url lib错误python

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(".") 
+0

检查这个问题一样:http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error – zwer

+0

@zwer我检查那,但我不确定import ssl如何在这里工作,你能帮忙吗? –

回答

0

最简单的解决问题的办法,你正在试图解决:使用HTTP,而不是HTTPS。

url = "http://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz" 

如果您更关心建立安全连接,那么@ zwer提到的帖子就是您所需要的。只要记住,urlretrieve接受关键字参数context只是方式urlopen