简体   繁体   English

Python SSL CERTIFICATE_VERIFY_FAILED

[英]Python SSL CERTIFICATE_VERIFY_FAILED

I'm using the following code to interact with a Magento webstore using the XMLRPC api.我正在使用以下代码通过 XMLRPC api 与 Magento 网络商店进行交互。 Magento API Python XMLRPC Magento API Python XMLRPC

Everything was working ok until we made a change on our web server to SSL一切正常,直到我们将 Web 服务器更改为 SSL

Now I'm getting the following error.现在我收到以下错误。

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581) ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:581)

I'm not sure why the certificate is failing as we have an EV certificate and all browsers are showing this as ok.我不确定为什么证书失败,因为我们有一个 EV 证书并且所有浏览器都显示为正常。

My connection string is:我的连接字符串是:

How can I resolve this / over-ride the code我该如何解决这个问题/覆盖代码

I'm fairly new to Python so please go easy :o)我对 Python 还很陌生,所以请放轻松 :o)

magento = MagentoAPI("www.website.co.uk", 443, "myUsername", "myPassword", "/api/xmlrpc", True)

Python, or better the OpenSSL library it is using, can not verify the validity of the certificate of the server. Python,或者更好的是它正在使用的OpenSSL库,无法验证服务器证书的有效性。 There are many possible reasons: bad configuration, missing intermediate or CA certificate, wrong CN... 可能有许多原因:配置错误,缺少中间证书或CA证书,错误的CN ...

A first step could be to go to this site and let it test the SSL/TLS capabilities of the server: https://www.ssllabs.com/ssltest/ 第一步可能是转到此站点,并使其测试服务器的SSL / TLS功能: https : //www.ssllabs.com/ssltest/

It will give you hints on how to solve problems as well. 它将为您提供有关如何解决问题的提示。

Python verifies certs via its own bundle, check where it is located by Python 通过自己的包验证证书,检查它的位置

>>> import certifi
>>> certifi.where()
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site- 
packages/certifi/cacert.pem'

and add your certificates to the end of that file.并将您的证书添加到该文件的末尾。

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

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