我正在尝试使用Zeep实现SOAP客户端,因为它似乎是目前唯一维护的库:
- ZSI看起来非常好,但其在pypi上的最新版本可以追溯到2006年。 - suds似乎是一个受欢迎的替代方案,但自2011年以来,其主要代码未得到维护,虽然有很多分支,但没有一个足够“官方”和“最新”,可以用于大型项目。
因此,尝试使用Zeep时,我被服务器要求进行身份验证才能访问WSDL所困扰。
使用ZSI进行此操作相当容易:
但在我的情况下不起作用,我会收到一个错误:
- ZSI看起来非常好,但其在pypi上的最新版本可以追溯到2006年。 - suds似乎是一个受欢迎的替代方案,但自2011年以来,其主要代码未得到维护,虽然有很多分支,但没有一个足够“官方”和“最新”,可以用于大型项目。
因此,尝试使用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 的 __main__.py 文件中找到了类似的东西:
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',))