You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python使用Zeep调用WebService遇[SSL: WRONG_VERSION_NUMBER]错误求助

问题

近期接手一个通过WebService推送数据的项目,安装了Python的Zeep库并编写测试代码验证连通性,但出现SSL版本错误。已将urllib3版本从最新降级至1.23,问题仍未解决,求解决建议。

测试代码:

from zeep import Client
wsdl = "https://10.110.168.102:20085/PY900/InvoiceProcessor?WSDL"
client = Client(wsdl)
print(client)

错误信息:

Traceback (most recent call last):
  File "urllib3\connectionpool.py", line 597, in urlopen
  File "urllib3\connectionpool.py", line 343, in _make_request
  File "urllib3\connectionpool.py", line 849, in _validate_conn
  File "urllib3\connection.py", line 349, in connect
  File "urllib3\util\ssl_.py", line 372, in ssl_wrap_socket
  File "ssl.py", line 500, in wrap_socket
  File "ssl.py", line 1040, in _create
  File "ssl.py", line 1309, in do_handshake
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "requests\adapters.py", line 489, in send
  File "urllib3\connectionpool.py", line 637, in urlopen
  File "urllib3\util\retry.py", line 398, in increment
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='10.110.168.102', port=20085): Max retries exceeded with url: /PY900/InvoiceProcessor?WSDL (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 20, in <module>
  File "zeep\client.py", line 76, in __init__
  File "zeep\wsdl\wsdl.py", line 92, in __init__
  File "zeep\wsdl\wsdl.py", line 95, in load
  File "zeep\wsdl\wsdl.py", line 155, in _get_xml_document
  File "zeep\loader.py", line 89, in load_external
  File "zeep\transports.py", line 123, in load
  File "zeep\transports.py", line 135, in _load_remote_data
  File "requests\sessions.py", line 600, in get
  File "requests\sessions.py", line 587, in request
  File "requests\sessions.py", line 701, in send
  File "requests\adapters.py", line 563, in send
requests.exceptions.SSLError: HTTPSConnectionPool(host='10.110.168.102', port=20085): Max retries exceeded with url: /PY900/InvoiceProcessor?WSDL (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))
[1692] Failed to execute script 'test' due to unhandled exception!

C:\Users\Administrator\Desktop\test\test>test
Traceback (most recent call last):
  File "urllib3\connectionpool.py", line 597, in urlopen
  File "urllib3\connectionpool.py", line 343, in _make_request
  File "urllib3\connectionpool.py", line 849, in _validate_conn
  File "urllib3\connection.py", line 349, in connect
  File "urllib3\util\ssl_.py", line 372, in ssl_wrap_socket
  File "ssl.py", line 500, in wrap_socket
  File "ssl.py", line 1040, in _create
  File "ssl.py", line 1309, in do_handshake
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "requests\adapters.py", line 489, in send
  File "urllib3\connectionpool.py", line 637, in urlopen
  File "urllib3\util\retry.py", line 398, in increment
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='10.110.168.102', port=20085): Max retries exceeded with url: /PY900/InvoiceProcessor?WSDL (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 20, in <module>
  File "zeep\client.py", line 76, in __init__
  File "zeep\wsdl\wsdl.py", line 92, in __init__
  File "zeep\wsdl\wsdl.py", line 95, in load
  File "zeep\wsdl\wsdl.py", line 155, in _get_xml_document
  File "zeep\loader.py", line 89, in load_external
  File "zeep\transports.py", line 123, in load
  File "zeep\transports.py", line 135, in _load_remote_data
  File "requests\sessions.py", line 600, in get
  File "requests\sessions.py", line 587, in request
  File "requests\sessions.py", line 701, in send
  File "requests\adapters.py", line 563, in send
requests.exceptions.SSLError: HTTPSConnectionPool(host='10.110.168.102', port=20085): Max retries exceeded with url: /PY900/InvoiceProcessor?WSDL (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))
[4800] Failed to execute script 'test' due to unhandled exception!
解决建议
  • 检查协议是否正确:wrong version number最常见的原因是用HTTPS访问了仅支持HTTP的服务。先把WSDL地址里的https改成http尝试:
    wsdl = "http://10.110.168.102:20085/PY900/InvoiceProcessor?WSDL"
    
  • 指定兼容的SSL版本:如果服务确实使用HTTPS,但SSL版本与本地客户端不兼容,可以自定义Zeep的Transport强制使用特定SSL版本:
    from zeep import Client
    from zeep.transports import Transport
    import requests
    from requests.adapters import HTTPAdapter
    from urllib3.poolmanager import PoolManager
    import ssl
    
    class SSLAdapter(HTTPAdapter):
        def init_poolmanager(self, connections, maxsize, block=False):
            self.poolmanager = PoolManager(
                num_pools=connections,
                maxsize=maxsize,
                block=block,
                ssl_version=ssl.PROTOCOL_TLSv1_2  # 根据服务实际支持版本调整,比如PROTOCOL_TLSv1_1
            )
    
    session = requests.Session()
    session.mount("https://", SSLAdapter())
    transport = Transport(session=session)
    
    wsdl = "https://10.110.168.102:20085/PY900/InvoiceProcessor?WSDL"
    client = Client(wsdl, transport=transport)
    print(client)
    
  • 临时跳过SSL验证(仅测试环境):如果是内部测试服务,证书不规范导致问题,可以临时关闭SSL验证,生产环境禁止使用:
    from zeep import Client
    from zeep.transports import Transport
    import requests
    
    session = requests.Session()
    session.verify = False
    transport = Transport(session=session)
    
    wsdl = "https://10.110.168.102:20085/PY900/InvoiceProcessor?WSDL"
    client = Client(wsdl, transport=transport)
    print(client)
    
  • 检查网络代理:若机器通过代理访问服务,代理可能篡改SSL请求导致版本不匹配,尝试关闭代理或在requests会话中配置正确的代理信息。
  • 确认服务端SSL配置:联系服务端维护人员,确认服务支持的SSL版本、证书有效性,以及端口是否确实绑定HTTPS服务。

内容的提问来源于stack exchange,提问作者user571102

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 08:10:16