Reputation: 43
I'm having trouble converting this XML to relevant python dictionary soap request for passing into Zeep.Client.service. The XML below comes from:
https://psix.uscg.mil/XML/PSIXData.asmx?op=getVesselSummaryXMLString
POST /XML/PSIXData.asmx HTTP/1.1
Host: psix.uscg.mil
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<getVesselSummaryXMLString xmlns="http://cgmix.uscg.mil">
<VesselID>string</VesselID>
<VesselName>string</VesselName>
<CallSign>string</CallSign>
<VIN>string</VIN>
<HIN>string</HIN>
<Flag>string</Flag>
<Service>string</Service>
<BuildYear>string</BuildYear>
</getVesselSummaryXMLString>
</soap12:Body>
</soap12:Envelope>
Ultimately I want to send a request to the soap server with the code below using a python dictionary as the "request_data" rather than the XML above, I'm just not sure which dictionary would be needed.
url = 'https://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL'
wsdl = url
client = zeep.Client(wsdl)
r = client.service.getVesselSummaryXMLString(request_data)
Upvotes: 1
Views: 2903
Reputation: 1461
you can inspect the wsdl methods by using this:
python -mzeep https://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL
from above, we can see that the getVesselSummaryXMLString
method takes only string arguments:
getVesselSummaryXMLString(VesselID: xsd:string, VesselName: xsd:string, CallSign: xsd:string, VIN: xsd:string, HIN: xsd:string, Flag: xsd:string, Service: xsd:string, BuildYear: xsd:string) -> getVesselSummaryXMLStringResult: xsd:string
So you can call it simply as passing string arguments just like a function call:
r = client.service.getVesselSummaryXMLString('str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8')
If you want to send the dictionary, then you need to prepare the dict as follows:
request_data = {'VesselID': 'str1', 'VesselName': 'string', 'CallSign': 'string', 'VIN': 'string', 'HIN': 'string', 'Flag': 'string', 'Service': 'string', 'BuildYear': 'str8'}
r = client.service.getVesselSummaryXMLString(**request_data )
hope this answers the question.
Upvotes: 2