Python SSL 错误:例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17084886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:23:52  来源:igfitidea点击:

SSL error : routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

pythonfilessl

提问by Sangamesh

I have a large number of file download links in a txtfile. I am trying to write a pythonscript to download all the files at once, but I end up with the following error:

我在一个txt文件中有大量的文件下载链接。我正在尝试编写一个python脚本来一次下载所有文件,但最终出现以下错误:

SSLError: [Errno 1] _ssl.c:499: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

The file is being downloaded via intranet.

该文件正在通过 Intranet 下载。

I tried to download the file via browser and I got a pop up with some certificate. I tried to google it but didn't find a way to solve this.

我尝试通过浏览器下载文件,但弹出了some certificate. 我试图谷歌它,但没有找到解决这个问题的方法。

回答by Remi Gacogne

The server certificate is invalid, either because it is signed by an invalid CA (internal CA, self signed,...), doesn't match the server's name or because it is expired.

服务器证书无效,要么是因为它是由无效的 CA(内部 CA、自签名等)签名的,要么是因为它与服务器的名称不匹配,要么是因为它已过期。

Either way, you need to find how to tell to the Python library that you are using that it must not stop at an invalid certificate if you really want to download files from this server.

无论哪种方式,您都需要找到如何告诉您正在使用的 Python 库,如果您真的想从该服务器下载文件,它不能停在无效的证书上。

回答by Stevenm

Experienced this myself when using requests:

使用时我自己经历过requests

This is extremely insecure; use only as a last resort!(See rdlowrey's comment.)

这是非常不安全的;仅作为最后手段使用!(见 rdlowrey 的评论。)

requests.get('https://github.com', verify=True)

Making that verify=Falsedid the trick for me.

verify=False做到这一点对我来说很有效。

回答by Hemant_Negi

Got this issue today and after wandering for several hours just came to know that my server datetime was wrong.

今天遇到了这个问题,徘徊了几个小时后才知道我的服务器日期时间是错误的。

So first please check your server datetime before going so deep in this issue.

因此,在深入研究此问题之前,请首先检查您的服务器日期时间。

also try doing

也尝试做

>> sudo update-ca-certificates

回答by desertkun

I've experienced the same issue because of certifilibrary. Installing a different version helped me as well.

由于certifi图书馆,我遇到了同样的问题。安装不同的版本也对我有帮助。

回答by ajon

Normally updating certifi and/or the certifi cacert.pemfile would work. I also had to update my version of python. Vs. 2.7.5 wasn't working because of how it handles SNI requests.

通常更新 certifi 和/或 certificacert.pem文件会起作用。我还必须更新我的 python 版本。对比 2.7.5 无法正常工作,因为它处理 SNI 请求的方式。

Once you have an up to date pem file you can make your http request using:

拥有最新的 pem 文件后,您可以使用以下方式发出 http 请求:

requests.get(url, verify='/path/to/cacert.pem')

requests.get(url, verify='/path/to/cacert.pem')

回答by Stef

could also happen when your local time is off (e.g. before certificate validation time), this was the case in my error...

当您的本地时间关闭时(例如在证书验证时间之前)也可能发生,这是我的错误中的情况...

回答by JimJty

Got this same error recently in a python app using requests on ubuntu 14.04LTS, that I thought had been running fine (maybe it was and some update occurred). Doing the steps below fixed it for me:

最近在使用 ubuntu 14.04LTS 上的请求的 python 应用程序中遇到了同样的错误,我认为它运行良好(也许是这样并且发生了一些更新)。执行以下步骤为我修复了它:

pip install --upgrade setuptools
pip install -U requests[security]

Here is a reference: https://stackoverflow.com/a/39580231/996117

这是一个参考:https: //stackoverflow.com/a/39580231/996117