简体   繁体   English

Python-问题SSL:CERTIFICATE_VERIFY_FAILED

[英]Python - Issue SSL: CERTIFICATE_VERIFY_FAILED

I'm trying to solve the problem 我正在尝试解决问题

requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)

when I connect to a handle server. 当我连接到句柄服务器时。

I also used 我也用过

ssl._create_default_https_context = ssl._create_unverified_context

as some user suggested, but I'm not able to fix the issue. 正如某些用户建议的那样,但我无法解决此问题。

Any other solution? 还有其他解决方案吗?

Thanks 谢谢

Does your server have a valid certificate, signed by a Certification Authority? 您的服务器是否具有由证书颁发机构签署的有效证书?

If it uses a self-signed certificate I would suggest that you save a copy of the public certificate in your Python project and pass the certificate name in the verify parameter on requests. 如果它使用自签名证书,则建议您将公共证书的副本保存在Python项目中,并在请求时在verify参数中传递证书名称。

You can save the certificate by accessing the server on Firefox, clicking on the Lock icon near to the address bar, selecting the Certificate, then More details, then View Certificate, then export. 您可以通过以下方法来保存证书:在Firefox上访问服务器,单击地址栏附近的“锁定”图标,依次选择“证书”,“更多详细信息”,“查看证书”和“导出”。

You will get a .pem file, let's say: "my_server_certificate.pem". 您将获得一个.pem文件,假设:“ my_server_certificate.pem”。

Then when you create your Session object on requests you can pass the parameter: 然后,当您在请求上创建Session对象时,可以传递参数:

session = requests.Session()
session.verify = "my_server_certificate.pem"

I had similar problems when using charles proxy with my Python scripts. 将charles代理与Python脚本一起使用时,我遇到了类似的问题。 I hope this helps you solve your problem as well. 我希望这也可以帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM