我正在尝试使用 zeep 访问 SOAP 服务器。我的服务器使用带有自定义证书的 SSL,并且可以使用我的证书连接到该服务器,或者忽略它:
python -mzeep "https://<server-ip>/servicemanager/1?wsdl" --no-verify
我得到了一长串前缀、全局元素、全局类型、绑定(bind)和服务。后一篇说:
Service: ServiceManager
Port: servicemanager_1 (Soap11Binding: {http://soap.client.<snipped>.at}servicemanager_1Binding)
Operations:
getServices() -> return: ns0:service[]
因此,据我现在所知,我可以创建一个 client
对象并调用其名为 getServices()
的服务。
from zeep import CachingClient as Client
from zeep.wsse.signature import Signature
from zeep.transports import Transport
from requests import Session, Request
session = Session()
session.verify = False
transport = Transport(session=session)
c = Client('https://<server-ip>/servicemanager/1?wsdl', transport=transport)
c.service.getServices()
但这会导致 urllib3 中出现错误(~/.virtualenvs/soap/lib/python3.5/site-packages/urllib3/util/connection.py):
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
[...]
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='localhost',
port=443): Max retries exceeded with url: /servicemanager/1 (Caused by
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object
at 0x7f4e2a6f7d30>: Failed to establish a new connection: [Errno 111]
Connection refused',))
忽略 SSL 验证或提供 CA_BUNDLE 都没有关系。两者都被接受,客户端已创建,但我无法调用 getServices()
方法。
我在这里忘记了什么?我不认为这是 zeep 问题,因为底层 urllib3 抛出异常。但我尝试了几个小时并在互联网上搜索解决方案,但没有成功。
我从端点获得的 XML 包括:
<service name="ServiceManager">
<port name="servicemanager_1" binding="tns:servicemanager_1Binding">
<soap:address location="http://localhost/servicemanager/1"/>
</port>
</service>
我不知道为什么它会返回一个“localhost” - zeep 是否使用它进行调用?然后我就会明白为什么会出现永久性错误。
有什么提示吗?
最佳答案
要更改端点地址,我这样使用它:
client.service._binding_options['address'] = 'https://mynewaddress.com/service.wsdl'
关于python-3.x - 使用 zeep SSL 时连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45265464/