how to specify xsi:type zeep python

荒凉一梦 提交于 2019-12-11 15:17:01

问题


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

ambCase = {'data1':'value1',
       'data2':'value2'}
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):

<soap-env:Body>
<ns0:AddCase xmlns:ns0="http://tempuri.org/">
  <ns0:guid>00000000-0000-0000-0000-000000000000</ns0:guid>
  <ns0:caseDto/>
</ns0:AddCase>

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


回答1:


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



来源:https://stackoverflow.com/questions/46502980/how-to-specify-xsitype-zeep-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!