python - 如何在 python zeep 中使用额外的 xsd?

标签 python xsd zeep spml

我需要实现 SPML接口(interface),最终通过 HTTP(s) 执行 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 请求来使用接口(interface)。我怎样才能让 zeep 知道那个(本地)xsd 文件?

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

最佳答案

是的,您可以通过以下方式将其他模式添加到您的 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()

关于python - 如何在 python zeep 中使用额外的 xsd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47704509/

相关文章:

python - 快速 pandas.DataFrame 初始化

python - 用于运行 pytest 的 Azure 自托管代理

xml - 异常 : src-resolve. 4.2:解析 xsd 中的组件时出错

Python发送和接收HTTP POST

python - 如何在Python中的主线程继续工作的情况下在单独的线程中实现阻塞监听功能

xml - XSD - 取决于属性值的子元素

java - XSD 验证 : This parser does not support specification "null" version "null"

python - 使用 Zeep 向 SOAP 服务发送原始 XML 请求(尝试复制参数)

python - 如何在 Python zeep 中指定 SOAP 服务器 URL

python - 如何使用zeep为签名添加时间戳?