2

I'm trying to create a custom SOAP header element using Zeep which uses several namespaces. When doing so, They are named ns0, ns1 and so on. For example:

usernametoken_header = xsd.Element('{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}UsernameToken', xsd.ComplexType([
    xsd.Attribute('{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Id', xsd.String()),
    xsd.Element('{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Username', xsd.String()),
    xsd.Element('{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Password', xsd.String())
    ]))

Will have ns0 for what is wsse, and ns1 for what is wsu. Now I want to rename them to those values, but without repositioning the namespace declaration. I also don't want to use UsernameToken. I am aware of the option to do:

client.set_ns_prefix('wsse', "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")

But this repositions the namespace declaration from the first child that uses it, up to the root node. I do not want such repositioning. Is there any way to do a in-place renaming of the namespace?

Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
  • What do you mean by "I also don't want to use `UsernameToken`." ? Also, are you trying to format a header for the zeep client to send to or receive from a SOAP service? – ryancdotnet Sep 21 '21 at 01:56

0 Answers0