1

我有以下 python 代码来设置 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>

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

4

2 回答 2

2
    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) 是您想要的关键点。

于 2018-09-28T08:57:54.617 回答
1

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

    xsd.Attribute(
        '{http://my-namespace}Id',xsd.String()
    ),
于 2017-06-16T05:40:46.133 回答