1. <small id='4l5ra'></small><noframes id='4l5ra'>

      <bdo id='4l5ra'></bdo><ul id='4l5ra'></ul>
  2. <legend id='4l5ra'><style id='4l5ra'><dir id='4l5ra'><q id='4l5ra'></q></dir></style></legend>
    <tfoot id='4l5ra'></tfoot>

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

    1. 在 Windows 上使用 python 请求的 SSL 失败

      时间:2023-11-07
    2. <tfoot id='5UQmW'></tfoot>
          <bdo id='5UQmW'></bdo><ul id='5UQmW'></ul>
          <legend id='5UQmW'><style id='5UQmW'><dir id='5UQmW'><q id='5UQmW'></q></dir></style></legend>
              <tbody id='5UQmW'></tbody>

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

                <small id='5UQmW'></small><noframes id='5UQmW'>

                本文介绍了在 Windows 上使用 python 请求的 SSL 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Apologies for the very long post, but I'm really trying to be thorough...

                I have a dedicated web site that serves as bridge to exchange data between various environmental models operated from remote servers and running on different types of OSes (Linux, MacOS and Windows). Basically each server can upload/download data files to the web site, and files are then used for further processing with a different model on another server.

                The web sites has some basic protection (IP filtering, password and SSL using LetsEncrypt certificates). All the remote servers can access the site and upload/download data through a simple web interface that we have created.

                Now we are trying to automate some of the exchange with a simple python (2.7) daemon (based on the requests module). The daemon monitors certain folders and uploads the content to the web site.

                The daemon works fine on all of the remote servers, except for one running Windows 7 Enterprise 64bit. This server has Python 2.7.13 installed and the following packages: DateTime (4.1.1), psutil (5.2.0), pytz (2016.10), requests (2.13.0), zope.interface (4.3.3).

                From this server the SSL connection works fine through a web browser, but the daemon always returns:

                raise SSLError(e, request=request)
                requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
                

                Here is what we tried so far:

                • setting verify=false. This works fine, but we cannot use it in our final production environment..
                • copying the certificate from another server where the daemon works, and setting verify=(name of the certificate file) (no success)
                • setting the 'User-agent' to the exact same string that we get from the Windows machine on the web site when the connection is done with a web browser (no success)

                What other setting should we be looking at on the Windows server to try to solve the problem? Can it be a firewall setting that somehow allows the browsers SSL connection through but blocks the python daemon?

                UPDATE
                The organization that is running the Windows remote server that was producing the error substitutes all SSL certificates at the proxy level.
                Their IT people solved our problem by adding the URL of our web site to the list of "pass through" sites on their proxy settings.

                This works and it's fine for now. However I'm wondering if we could have handled the certificate substitution directly in python...

                解决方案

                It is possible to get the Requests library to use Python's inbuilt ssl module to make the SSL portion of the HTTP connection. This is doable because the urllib3 utils that Requests uses allow passing a Python SSLContext into them.

                However, note that this may depend on the necessary certificates already being loaded into the trust store based on a previous Windows access (see this comment)

                Some sample code follows (this needs a recent version of Requests; it works with 2.18.4):

                import requests
                from requests.adapters import HTTPAdapter
                from requests.packages.urllib3.util.ssl_ import create_urllib3_context
                
                class SSLContextAdapter(HTTPAdapter):
                    def init_poolmanager(self, *args, **kwargs):
                        context = create_urllib3_context()
                        kwargs['ssl_context'] = context
                        context.load_default_certs() # this loads the OS defaults on Windows
                        return super(SSLContextAdapter, self).init_poolmanager(*args, **kwargs)
                
                s = requests.Session()
                adapter = SSLContextAdapter()
                s.mount('https://myinternalsite', adapter)
                response = s.get('https://myinternalsite')
                

                这篇关于在 Windows 上使用 python 请求的 SSL 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:请求:cert 和 verify 有什么区别? 下一篇:python中的简单DER证书解析

                相关文章

                  <bdo id='BM9gs'></bdo><ul id='BM9gs'></ul>

                1. <tfoot id='BM9gs'></tfoot>

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

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