代码之家  ›  专栏  ›  技术社区  ›  geckels1

Zeep的SSL错误-如何更改密码套件?

  •  1
  • geckels1  · 技术社区  · 2 年前

    我正试图使用Zeep加载WSDL文件,但当我这样做时,我收到以下错误:

    requests.exceptions.SSLError: HTTPSConnectionPool(host='api-mte.itespp.org', port=443): Max retries exceeded with url: /markets/VirtualService/v2/?WSDL (Caused by SSLError(SSLError(1, '[SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:997)')))
    

    我读了另一个答案( Python - requests.exceptions.SSLError - dh key too small )这可以使用不同的密码套件来解决(因为我认为服务器很旧,这就是导致这个错误的原因),但我不知道如何使用Zeep来做到这一点。有什么想法吗?谢谢

    0 回复  |  直到 2 年前
        1
  •  0
  •   geckels1    2 年前

    答案与我所问的[另一个问题][1]基本相同 zeep 使用 requests 模块,使用后 请求: 要获得所需的密码,只需将该会话应用于 zeep 。下面是我使用的代码示例。

    # Define wsdl file
    
    # Define the custom cipher suites you want to use
    custom_cipher_suite = [
        "ECDHE-RSA-AES256-GCM-SHA384",
    #    "DHE-RSA-AES256-GCM-SHA384",
    #    "ECDHE-RSA-AES128-GCM-SHA256"
    #    "TLS_AES_256_GCM_SHA384"
    ]
    
    class CustomCipherAdapter(HTTPAdapter):
        def init_poolmanager(self, *args, **kwargs):
            context = create_urllib3_context(ciphers=":".join(custom_cipher_suite))
            kwargs['ssl_context'] = context
            return super(CustomCipherAdapter, self).init_poolmanager(*args, **kwargs)
    
    # Create a session and mount the adapter
    session = requests.Session()
    session.mount("https://", CustomCipherAdapter())
    
    client = zeep.Client(wsdl=wsdl, transport=zeep.Transport(session=session))
    
    
      [1]: https://stackoverflow.com/questions/77262501/how-to-alter-cipher-suite-used-with-python-requests/77270120#77270120
    
    推荐文章