• <i id='DOlZZ'><tr id='DOlZZ'><dt id='DOlZZ'><q id='DOlZZ'><span id='DOlZZ'><b id='DOlZZ'><form id='DOlZZ'><ins id='DOlZZ'></ins><ul id='DOlZZ'></ul><sub id='DOlZZ'></sub></form><legend id='DOlZZ'></legend><bdo id='DOlZZ'><pre id='DOlZZ'><center id='DOlZZ'></center></pre></bdo></b><th id='DOlZZ'></th></span></q></dt></tr></i><div id='DOlZZ'><tfoot id='DOlZZ'></tfoot><dl id='DOlZZ'><fieldset id='DOlZZ'></fieldset></dl></div>
    <tfoot id='DOlZZ'></tfoot>

    1. <legend id='DOlZZ'><style id='DOlZZ'><dir id='DOlZZ'><q id='DOlZZ'></q></dir></style></legend>

      1. <small id='DOlZZ'></small><noframes id='DOlZZ'>

        • <bdo id='DOlZZ'></bdo><ul id='DOlZZ'></ul>

        Python 请求 SSL 错误 - 证书验证失败

        时间:2023-11-07

            <tbody id='Hsu5r'></tbody>

        • <tfoot id='Hsu5r'></tfoot>

        • <legend id='Hsu5r'><style id='Hsu5r'><dir id='Hsu5r'><q id='Hsu5r'></q></dir></style></legend>
          <i id='Hsu5r'><tr id='Hsu5r'><dt id='Hsu5r'><q id='Hsu5r'><span id='Hsu5r'><b id='Hsu5r'><form id='Hsu5r'><ins id='Hsu5r'></ins><ul id='Hsu5r'></ul><sub id='Hsu5r'></sub></form><legend id='Hsu5r'></legend><bdo id='Hsu5r'><pre id='Hsu5r'><center id='Hsu5r'></center></pre></bdo></b><th id='Hsu5r'></th></span></q></dt></tr></i><div id='Hsu5r'><tfoot id='Hsu5r'></tfoot><dl id='Hsu5r'><fieldset id='Hsu5r'></fieldset></dl></div>

              • <bdo id='Hsu5r'></bdo><ul id='Hsu5r'></ul>
                • <small id='Hsu5r'></small><noframes id='Hsu5r'>

                  本文介绍了Python 请求 SSL 错误 - 证书验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这段代码

                  导入请求requests.get("https://hcaidcs.phe.org.uk/WebPages/GeneralHomePage.aspx")

                  给我这个错误

                  [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:777)

                  我对 SSL 几乎一无所知,但我尝试下载站点的证书并使用 verify 选项指向该文件,但没有成功.我错过了什么吗?

                  解决方案

                  正如评论中已经指出的那样:从 SSLLabs 报告.这份报告中关于您的问题的主要部分是:

                  <块引用>

                  此服务器的证书链不完整.等级上限为 B.

                  这意味着服务器没有发送验证证书所需的完整证书链.这意味着您需要在验证时自己添加缺少的证书.为此,您需要包含缺失链证书的 PEM C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert SHA2 High Assurance Server CA 以及根 CA C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA info a file my_trust_store.pem 然后您可以调用:

                  requests.get("https://...", verify='my_trust_store.pem')

                  <块引用>

                  ...但我已尝试下载该站点的证书并使用验证选项指向该文件

                  这不适用于普通的叶子证书.由于 Python 的 SSL 堆栈基于 OpenSSL,而 OpenSSL 只需要信任库中的受信任证书颁发机构(即使用 verify 给出)并且服务器证书不是 CA 证书,因此将其添加到信任库.

                  This code

                  import requests
                  requests.get("https://hcaidcs.phe.org.uk/WebPages/GeneralHomePage.aspx")
                  

                  is giving me this error

                  [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
                  

                  I know practically nothing about SSL, but I've tried downloading the site's certificate and pointing to that file using the verify option, but it hasn't worked. Am I missing something?

                  解决方案

                  As already pointed out in a comment: the site has a bad SSL implementation as can be seen from the SSLLabs report. The main part of this report regarding your problem is:

                  This server's certificate chain is incomplete. Grade capped to B.

                  This means that the server is not sending the full certificate chain as is needed to verify the certificate. This means you need to add the missing certificates yourself when validating. For this you need to include the PEM for the missing chain certificate C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert SHA2 High Assurance Server CA and also for the root CA C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA info a file my_trust_store.pem and then you can call:

                  requests.get("https://...", verify='my_trust_store.pem')
                  

                  ... but I've tried downloading the site's certificate and pointing to that file using the verify option

                  This will not work with normal leaf certificates. Since the SSL stack of Python is based on OpenSSL and OpenSSL expects only trusted certificate authorities in the trust store (i.e. given with verify) and a server certificate is not CA certificate it will not help to add it to the trust store.

                  这篇关于Python 请求 SSL 错误 - 证书验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用带有 TLS 的请求不会提供 SNI 支持 下一篇:pip install failed with SSL certificate verify failed (_ssl.

                  相关文章

                  <tfoot id='gmH5L'></tfoot>

                      <small id='gmH5L'></small><noframes id='gmH5L'>

                      • <bdo id='gmH5L'></bdo><ul id='gmH5L'></ul>
                      <legend id='gmH5L'><style id='gmH5L'><dir id='gmH5L'><q id='gmH5L'></q></dir></style></legend>
                    1. <i id='gmH5L'><tr id='gmH5L'><dt id='gmH5L'><q id='gmH5L'><span id='gmH5L'><b id='gmH5L'><form id='gmH5L'><ins id='gmH5L'></ins><ul id='gmH5L'></ul><sub id='gmH5L'></sub></form><legend id='gmH5L'></legend><bdo id='gmH5L'><pre id='gmH5L'><center id='gmH5L'></center></pre></bdo></b><th id='gmH5L'></th></span></q></dt></tr></i><div id='gmH5L'><tfoot id='gmH5L'></tfoot><dl id='gmH5L'><fieldset id='gmH5L'></fieldset></dl></div>