【发布时间】:2016-10-21 09:38:40
【问题描述】:
我正在尝试使用 Zeep 来实现一个 SOAP 客户端,因为它似乎是目前唯一维护的库:
- ZSI 看起来很不错,但它在 pypi 上的最新版本日期为 2006 年
- suds 似乎是一个流行的替代方案,但 master 自 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',))
【问题讨论】:
-
就我而言,我必须通过 _soapheaders 发送它。请查看我的answer.
-
@Pintun 您能否更改已接受的答案,因为当前答案已过时
标签: python authentication soap wsdl