如何使用 zeep 添加 wsu:Id 属性?

How to add wsu:Id attribute using zeep?

我有以下 python 代码来设置 header SOAP 请求:

ebsheader = xsd.Element(
    '{http://ebs.health.ontario.ca/}EBS',
    xsd.ComplexType([
        xsd.Attribute(
            'Id',xsd.String()
        ),
        xsd.Element(
            'SoftwareConformanceKey', xsd.String()
        ),
        xsd.Element(
            'AuditId', xsd.String()
        ),
    ])
)
headers = []
headers.append(ebsheader('id-1','software-key-here','unique-id'))

它产生以下 xml:

<ns0:EBS xmlns:ns0="http://ebs.health.ontario.ca/" Id="id-1">
  <SoftwareConformanceKey>software-key-here</SoftwareConformanceKey>
  <AuditId>unique-id</AuditId>
</ns0:EBS>

但是,我需要 wsu:Id="id-1" 而不是 Id="id-1"。我需要在 header 中指定哪个参数才能完成此操作?

你需要传递一个命名空间,例如

    xsd.Attribute(
        '{http://my-namespace}Id',xsd.String()
    ),
    settings = Settings(strict = False, xml_huge_tree = True)
    client = Client(wsdl_path, transport = self.transport, wsse = self.wsse,settings = settings)
    client.set_ns_prefix(ns_prefix,namespace)
    service = client.create_service('{{{}}}{}'.format(namespace, binding_name), xaddr)

client.set_ns_prefix(ns_prefix,namespace) 关键点你要什么