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

问题描述 投票:0回答:1

我正在尝试使用 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太小),这可以使用不同的密码套件来解决(因为我认为服务器很旧,这就是导致此错误的原因),但是我不知道如何使用 Zeep 来做到这一点。有任何想法吗?谢谢!

python ssl openssl wsdl zeep
1个回答
0
投票

答案与我问的[另一个问题][1]基本相同,因为

zeep
使用
requests
模块,并且在使用
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
© www.soinside.com 2019 - 2024. All rights reserved.