Александр Александр - 2 years ago 351
Python Question

how to specify xsi:type zeep python

Im using zeep SOAP client for python, trying to get some data to some wsdl_address. i now have following:

ambCase = {'data1':'value1',
client = zeep.Client(wsdl=WSDL_Address)
result = client.service.MethodName(GUID, {'CaseDto':ambCase})

where ambCase is data i want to get to the server. MethodName method requires 2 parameters: GUID token(which works no problem), and ambCase object with specified xsi:type attribute(in my case it should be 'CaseAmb'), and i can't get it to work, it fails with an error:
zeep.exceptions.Fault: exception str() failed

code above produces this xml(excepting headers):

<ns0:AddCase xmlns:ns0="http://tempuri.org/">

I'm pretty new to SOAP and zeep, so, can anyone help?

Answer Source

By trial and error the following combination worked:

objectType = client.get_type('ns6:someTypeName') # someTypeName will be in xsi:type attribute
objectWrap = xsd.Element('xmlTagName',objectType) # xmlTagName - name of created xml element
objectValue = objectWrap('param1',param2,param3[0]) # putting actual data values into object
client = zeep.Client(wsdl)
result = client.service.MethodName(objectValue) # calling  some method with your object(with explicitly detrmined type) as param

The thing is, if you pass a dict as method param, zeep will create that object himself(without type), if you want to determine type - create that object by yourself

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download