我正在尝试使用Zeep
访问SOAP Web服务有一个公开的WSDL和一个testing WSDL(有一个自签名的证书)
我要测试的代码(来自测试网站)是:
from requests import Session
from zeep import Client
from zeep.transports import Transport
from zeep.wsse.username import UsernameToken
import xml.dom.minidom
WS_USER_NAME = '<username>'
WS_PASSWORD = '<password>'
WS_WSDL = 'https://pre.ipddb.org/WS/Services/IpdDownloadService.svc?wsdl'
session = Session()
session.verify = False
transport = Transport(session=session,
operation_timeout=10)
client = Client(wsdl=WS_WSDL,
wsse=UsernameToken(WS_USER_NAME, WS_PASSWORD),
transport=transport)
with client.options(raw_response=True):
response = client.service.Search(strNames='Rick Astley')
xml = xml.dom.minidom.parseString(response._content)
print xml.toprettyxml()
我的回复是:
<?xml version="1.0" ?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
<a:RelatesTo>urn:uuid:5ffbeb15-913b-41ec-a2ef-556c131c07eb</a:RelatesTo>
</s:Header>
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="es-ES">The message could not be processed. This is most likely because the action 'https://www.ipddb.org/ws/IpdDownloadService/Search' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</s:Text>
</s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>
我从Web服务的所有者那里获得了一个用户名和密码,所以我知道我需要提供这个,但是必须有一些我不知道的东西。我认为它与WSDL中定义的策略有关,但Web服务在文档方面没有提供任何内容。
我是SOAP的新手,但是我在WSDL中有足够的数据来确定他们需要遵守的政策吗?
我是否可以使用Zeep来完成所有政策?
我是否需要维护网络服务的人员提供更多信息?
答案 0 :(得分:0)
并非这是对您的问题的直接回答,但是当我必须提出肥皂请求时,我希望使用soapui来熟悉API。
为soapui提供WSDL后,它将自动为正确的请求生成所有必需的参数。通过这样做,您可以验证您收到的错误是由于系统策略而不是因为zeep。