我试图使用Zeep来实现一个SOAP客户端,因为它似乎是目前唯一维护的库:
因此,尝试使用Zeep时,我被服务器访问WSDL所需的身份验证所困扰。
这种操作在ZSI中相当简单:
from ZSI.client import Binding
from ZSI.auth import AUTH
b = Binding(url='http://mysite.dom/services/MyWebServices?WSDL')
b.SetAuth(AUTH.httpbasic, 'userid', 'password')
我可以在Zeep的主目录中找到类似的东西:
from six.moves.urllib.parse import urlparse
from zeep.cache import InMemoryCache, SqliteCache
from zeep.client import Client
from zeep.transports import Transport
cache = SqliteCache() if args.cache else InMemoryCache()
transport_kwargs = {'cache': cache}
result = urlparse(args.wsdl_file)
if result.username or result.password:
transport_kwargs['http_auth'] = (result.username, result.password)
transport = Transport(**transport_kwargs)
client = Client(args.wsdl_file, transport=transport)
但这在我的情况下不起作用,我得到一个错误:
Exception: HTTPConnectionPool(host='schemas.xmlsoap.org', port=80): Max retries exceeded with url: /soap/encoding/ (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f3dab9d30b8>: Failed to establish a new connection: [Errno 110] Connection timed out',))
对于基本访问身份验证,可以使用
requests
模块中的HTTPBasicAuth
类,如Zeep文档http://docs.python-zeep.org/en/master/transport.html中所述:可能对于较新版本的zeep,较旧的解决方案不再工作。Here is the new way:
在我的例子中,我使用的是必需的WS-Security(WSSE),而不是HTTP。
相关问题 更多 >
编程相关推荐