python - url库错误python

标签 python python-3.x ssl

我正在尝试通过 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/

相关文章:

python - 大型 django 项目的项目设计/FS 布局

python - 如何防止 PyCharm 覆盖 matplotlib 中设置的默认后端?

vb.net - SOAP 错误 : The request was aborted: Could not create SSL/TLS secure channel

ruby-on-rails - Docker(docker-compose)应用程序容器中的 LetsEncrypt 不起作用

python - 数据库连接: with closing() vs __del__

python - 如何使用 Django 过滤一对一的通用关系?

python - pandas dtype 和 dtypes 有什么区别

python - Python 中 "import as"的用例

python - VirtualEnv apache2 服务器没有名为 'django' 的模块

Selenium firefox 驱动力 https