简体   繁体   中英

SOAP - Create an element with zeep (python)

I've to use a SOAP API for a project. For a specific method I've to send a complex type.

This complex type is declared like that:

<complexType name="specialList">
    <sequence>
        <element name=data" minOccurs="0"maxOccurs="unbounded">
            <complexType>
                <simpleContent>
                    <extension base="string">
                        <attribute name="key" type="string" use="required"/>
                    </extension>
                </simpleContent>
            </complexType>
        </element>
    </sequence>
</complexType>

This is an example:

<my_action type="specialList">
    <data key="myKey">MyValue</data>
    <data key="myOtherKey">MyOtherValue</data>
</my_action>

To access to the SOAP API, I use zeep (I tried with suds). The first think I do is retrieve my "specialList".

special_list = client.get_type('ns1:specialList')
my_action = special_list(data=[data_1, data_2])

However I've a problem with the type "data". Indeed this type "data" is not declared. I cannot do a client.get_type("ns1:data").

I tried several time to create an simple element but without success. Do you have an idea how to create this "special" data ?

In advance, thank you.

Sylvain

can you try using AnyObject as indicated in their documentation: http://docs.python-zeep.org/en/master/datastructures.html

so in your code:

from zeep import xsd

special_list = client.get_type('ns1:specialList')
my_action = xsd.AnyObject(special_list, special_list(data=[data_1, data_2]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM