问题
I'm trying to access a SOAP web service using Zeep
There is a publicly available WSDL, and a testing WSDL (has a self-signed cert)
My code to test (from test site) is:
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()
My response comes back as:
<?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>
I was provided a username and password from the owners of the web service, so I know I'll need to provide that, but there must be something else I'm missing. I believe it has to do with the policy defined in the WSDL, but the web service doesn't provide anything in terms of documentation.
I'm new to SOAP, but is there enough in the WSDL for me to figure what they need to comply with policy?
Will I be able to use Zeep to fulfill all the policies?
Do I need more info from those maintaining the web service?
回答1:
Not that it's a direct answer to your question, but when I have to make a soap request I like to familiarize myself with the API by using soapui.
Once you provide a WSDL for soapui, it will automatically generate all of the required parameters for a proper request. By doing so, you can validate that the error you're receiving is because of a system policy and not because of zeep.
来源:https://stackoverflow.com/questions/44330748/how-to-comply-with-policy-defined-in-wsdl