mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 578 forks source link

How to remove extra element when using _soapheaders=[...] #1306

Open antonio83moura opened 2 years ago

antonio83moura commented 2 years ago

Hi All,

I've been trying to use the xsd.Element to customize the header via _soapheaders. But it creates a new element Header under the that already exists.

Any Idea how to avoid this problem?

The new header is created using the code below.

header = xsd.Element(
    'Header',
    xsd.ComplexType(
        xsd.Sequence([
            xsd.Element(
                name='{http://schemas.xmlsoap.org/ws/2004/08/addressing}Action',
                type_=xsd.String()
            ),
            xsd.Element(
                name='{http://schemas.xmlsoap.org/ws/2004/08/addressing}To',
                type_=xsd.String()
            ),
            xsd.Element(
                name='fueloauth',
                type_=xsd.String()
            )
        ])
    )
    # attr_name="Header",
    # is_global=True
)
header_value = header(Action="Retrieve", To=url_amsx, fueloauth=token)

output:

<s:Header>
        <Header>
            <a:Action s:mustUnderstand="1">Retrieve</a:Action>
            <a:To s:mustUnderstand="1"

Thank you