我如何在python zeep中使用附加的xsd?

问题描述 投票:3回答:1

我需要实现一个SPML接口,该接口最终正在通过HTTP执行SOAP请求。我有一个wsdl可以归结为:

<wsdl:types>
  <schema targetNamespace="http://soapadapter.something" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="receiveRequest" type="xsd:anyType"/>
  </schema>
</wsdl:types>
[...]
<wsdl:operation name="receiveRequest">
 <wsdl:input message="impl:receiveRequestRequest" name="receiveRequestRequest"/>
</wsdl:operation>

如您所见,唯一定义的请求元素是“ xsd:anyType”类型。我有一个单独的xsd,在wsdl中根本没有链接,它描述了如何形成请求。

我想使用zeep来实现使用接口的SOAP请求。如何使zeep知道该(本地)xsd文件?

我已经找到了zeep.xsd.schema.SchemaDocument类,但没有在任何地方使用它的示例。有人可以给我一个使用示例,说明如何创建使用wsdl和单独的xsd文件的客户端吗?

python xsd zeep spml
1个回答
1
投票
是,您可以通过以下方式将其他架构添加到您的zeep客户端:

import os from zeep.loader import load_external from zeep import Client XSD_SCHEMA_FILE = "/path/to/your.xsd" CONTAINER_DIR = os.path.dirname(XSD_SCHEMA_FILE) # Where to load dependencies if any client = Client('https://path/to/your.wsdl') schema_doc = load_external(open(XSD_SCHEMA_FILE, "rb"), None) doc = client.wsdl.types.create_new_document(schema_doc, f"file://{CONTAINER_DIR}") doc.resolve()

© www.soinside.com 2019 - 2024. All rights reserved.