Python SSL:CERTIFICATE_VERIFY_FAILED [英] Python SSL: CERTIFICATE_VERIFY_FAILED

查看:75
本文介绍了Python SSL:CERTIFICATE_VERIFY_FAILED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Windows 8.1 的相当新的机器上使用 Python 2.7.12 连接到 www.mydomain.com 时出现错误.下面代码的 ssl_sock.connect 行上的错误是 SSL: CERTIFICATE_VERIFY_FAILED.代码在上下文中包装了 SSL 连接,并指定我不想进行证书验证:

I'm getting an error when connecting to www.mydomain.com using Python 2.7.12, on a fairly new machine that uses Windows 8.1. The error is SSL: CERTIFICATE_VERIFY_FAILED on the ssl_sock.connect line of the code below. The code wraps an SSL connection in an context, and specifies I don't want to carry out certificate verification:

ssl._create_default_https_context = ssl._create_unverified_context
s_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_NONE
context.check_hostname = True
context.load_default_certs()

ssl_sock = context.wrap_socket(s_, server_hostname=myurl)
ssl_sock.connect((myurl, int(myportno)))

我尝试将来自我尝试连接的服务器的纯文本版本的安全证书添加到 Python 引用的默认证书文件中 - 这不起作用(无论如何,它不起作用我应该这样做是有道理的)

I've tried adding the plain text version of the security certificate from the server I'm trying to connect to, to the default certificate file that Python references - that didn't work (in any case, it doesn't make sense that I should need to do this)

当我浏览到我尝试连接的域时,浏览器也不信任远程服务器证书,但是我已经检查了绑定到域的证书并且验证正常.什么可能导致不信任?(我目前正在调查从出现错误的机器上删除 Windows 安全补丁,看看这是否可能是原因)

When I browse to the domain I'm trying to connect to, the browser also doesn't trust the remote server certificate, however I've examined the certificate that's bound to the domain and it's validating fine. What could be causing the mistrust? (I'm currently investigating removal of a Windows security patch from the machine where I'm getting the error, to see if that could be the cause)

(此问题在使用相同代码的其他计算机上出现过,但在 Windows 检索完整更新集后似乎可以解决.但问题仍然存在的机器也有完整更新集)

(this issue has occurred on other computers using the same code, however it seems to resolve after Windows retrieves a full set of updates. The machine where the problem is persisting also has a full set of updates however)

推荐答案

我解决了这个问题,这似乎与 2016 年 8 月 29 日发布的 Windows 安全更新有关,该更新导致在使用 TLS 1.0 协议时出现证书验证问题.在没有安全更新的情况下重新安装 Windows 至少可以让事情暂时工作.在 Windows 10 下运行时我也没有遇到这个问题

I resolved this issue, which seems to be related to a post Aug 29th 2016 security update for Windows that causes issues with certificate verification when using the TLS 1.0 protocol. Re-installing Windows without the security update at least allows things to work for now. Also I didn't get this issue when running under Windows 10

这篇关于Python SSL:CERTIFICATE_VERIFY_FAILED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆