pythonsoapwsdlzeep

Set any type from WSDL in Zeep SOAP request


I have WSDL envelope like this:

...
<xs:complexType name="hilfsmittelattribute">
    <xs:sequence>
        <xs:any maxOccurs="unbounded" namespace="http://hma.ws.bswsnt.vsa/xsd" processContents="skip"/>
    </xs:sequence>
</xs:complexType>
...

What I would like to do is something like this

conn = zeep.Client(...)
data = {
    ....
    'hilfsmittelattribute': {'koerperhaelfte': 1}
    ...
}
pack = conn.service.someMethod(**data)

but I get error that

TypeError: ... got an unexpected keyword argument 'koerperhaelfte'. Signature: `_value_1: ANY[]`

I read documentation from here Zeep documentation for Any

But:

if I do:

conn.get_element('ns0:hilfsmittelattribute') # or ns1, ns2, ns3...

I get

LookupError: No element 'hilfsmittelattribute' in namespace http://ws.bswsnt.vsa/xsd. Available elements are:  -

But if I write

hilfsmittelattribute_type = conn.get_type('ns2:hilfsmittelattribute')

I get the type object

( the code return )

hilfsmittelattribute_type.elements
>> [('_value_1', <Any(name=None)>)]

but if I would like to use this type object like this

hilfsmittelattribute_ = xsd.AnyObject(
    hilfsmittelattribute_type, hilfsmittelattribute_type(koerperhaelfte='1'))

I get the error

TypeError: {...}hilfsmittelattribute() got an unexpected keyword argument 'koerperhaelfte'. Signature: `_value_1: ANY[]`

EDIT:

I try to create SOAP envelope by hand. If I set :

....
<hilfsmittelattribute>
    <koerperhaelfte>5</koerperhaelfte>
</hilfsmittelattribute>
....

It actually works... So the problem needs to be in Zeep on handling Any type.


Solution

  • If anyone has still trouble with this...

    The fix is to create custom etree element

    import lxml.etree as ET
    koerperhaelfte_element = ET.Element("koerperhaelfte")
    koerperhaelfte_element.text = "rechts"
    

    and then use it inside json

    'hilfsmittelattribute': {
          "_value_1": [koerperhaelfte_element],
    },