- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 Zeep 来描述给定 WSDL 中的操作和类型,以便程序知道操作名称、它们的参数名称、参数类型和参数属性。
此信息将用于为给定的 WSDL 动态生成 UI。
到目前为止,我得到的只是操作和类型的字符串表示。使用类似于 this answer 中的代码.
这是一个例子:
from zeep import Client
import operator
wsdl = 'http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl'
client = Client(wsdl)
# get each operation signature
for service in client.wsdl.services.values():
print("service:", service.name)
for port in service.ports.values():
operations = sorted(
port.binding._operations.values(),
key=operator.attrgetter('name'))
for operation in operations:
print("method :", operation.name)
print(" input :", operation.input.signature())
print()
print()
# get a specific type signature by name
complextype = client.get_type('ns0:CartGetRequest')
print(complextype.name)
print(complextype.signature())
这给出如下输出(为简洁起见缩短)
[...]
method : CartCreate
input : MarketplaceDomain: xsd:string, AWSAccessKeyId: xsd:string, AssociateTag: xsd:string, Validate: xsd:string, XMLEscaping: xsd:string, Shared: ns0:CartCreateRequest, Request: ns0:CartCreateRequest[]
method : CartGet
input : MarketplaceDomain: xsd:string, AWSAccessKeyId: xsd:string, AssociateTag: xsd:string, Validate: xsd:string, XMLEscaping: xsd:string, Shared: ns0:CartGetRequest, Request: ns0:CartGetRequest[]
[...]
CartGetRequest
{http://webservices.amazon.com/AWSECommerceService/2011-08-01}CartGetRequest(CartId: xsd:string, HMAC: xsd:string, MergeCart: xsd:string, ResponseGroup: xsd:string[])
.signature() 返回的字符串表示具有名称和类型,但我不知道如何将它们单独解析出来。我也尝试过使用 dir() 遍历每个对象属性,但它们不包含此信息。它似乎嵌套得更深。
我可以自己解析字符串表示,但是我也不知道参数是否是可选的(更具体地说,如果它具有属性 minOccurs=0
好像SOAPpy actually has this functionality , 但不再维护。
那么有没有一种方法可以使用 zeep 来检查 WSDL,它提供关于每个操作的详细信息,它的参数名称、类型和类似于 SOAPpy 实现的属性?或者我应该解析签名,或者使用常规 XML 解析器解析 WSDL。
最佳答案
根据 jordanm 的回答,我使用以下方法获取可用方法所需的所有数据
from zeep import Client
from pprint import pprint
wsdl = 'http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl'
client = Client(wsdl)
def parseElements(elements):
all_elements = {}
for name, element in elements:
all_elements[name] = {}
all_elements[name]['optional'] = element.is_optional
if hasattr(element.type, 'elements'):
all_elements[name]['type'] = parseElements(
element.type.elements)
else:
all_elements[name]['type'] = str(element.type)
return all_elements
interface = {}
for service in client.wsdl.services.values():
interface[service.name] = {}
for port in service.ports.values():
interface[service.name][port.name] = {}
operations = {}
for operation in port.binding._operations.values():
operations[operation.name] = {}
operations[operation.name]['input'] = {}
elements = operation.input.body.type.elements
operations[operation.name]['input'] = parseElements(elements)
interface[service.name][port.name]['operations'] = operations
pprint(interface)
关于python - 使用 Python Zeep 反省 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50089400/
我想用 Zeep 解析一个 WSDL 文件并退出: 所有操作 为每个操作请求 xml 消息 有关解析 wsdl 的任何示例? 我想我应该使用 zeep.wsdl 和 parse_service 方法?
Python SOAP客户端库Zeep支持附件吗? 我在 documentation 中真的找不到任何东西. 想法是以 XML 格式发送带有一些附件的 SOAP 请求。我想这样做的常规方法是一条多部分
我正在使用 Python zeep发出 SOAP 请求。对于 SSL 验证,HostHeaderSSLAdapter添加为我的 URL https://dev_alias:8096/some_soap
我的 SOAP 服务将使用各种无效负载进行测试,以确认返回适当的响应。 在进行测试之前,我想对我的服务进行自己的测试。一些测试涉及删除必填字段。我想使用 zeep 模拟这些测试,但 zeep 不允许我
我一直在使用 python zeep 检查 WSDL 文档并生成相应的代码以使用 wsdl 文档中的服务和类型。 下面的代码是一个简短的例子。它部分起作用。问题是:这些参数并不是 web 服务正在等待
我正在尝试创建一个使用 WSDL 文件并生成适当的 SOAP 消息的客户端。这就是我创建客户端的方式: client = Client( wsdl=wsdl ,tran
我尝试使用 python-zeep 包来使用一些肥皂服务( ID3 Global ) 这似乎是可行的,对最近添加的功能(WSSE 身份验证和使用多个绑定(bind)的可能性)表示赞赏 现在,我尝试循环
我正在为一段使用 zeep 访问 SOAP API 的代码编写单元测试,因此我想模拟 zeep。在我的实际代码中,它看起来像这样: from zeep import Client def do_som
我有两个单独的 WSDL 文件提供给我以与服务交互,一个 WSDL 文件只提供一种登录和生成访问 token 的方法。另一个 WSDL 文件提供了与系统实际交互的方法。 如果我用要登录的第一个 WSD
我正在尝试连接到 SOAP 网络服务并使用 pandas 放在 table 上。 Zeep 给我这个列表: [{ 'ssPeca': '103', 'ssQtd': '1',
当我运行以下代码时,我不断收到以下错误:here is an error in XML document (113, 25)。 ---> 字符串 '' 不是有效的 bool 值。 我不明白为什么会这样
我有使用 zeep 创建肥皂客户端的代码。我的服务器没有返回 wsdl 文件,但我在本地有它。 同步版本的工作原理如下: import uuid from os import path import
我正在使用 zeep 调用 SOAP 网络服务。即使该方法存在于 WSDL 中,它也会抛出错误 client = Client(self.const.soap_url) client.service.
我需要实现 SPML接口(interface),最终通过 HTTP(s) 执行 SOAP 请求。我有一个 wsdl 可以归结为: [...] 如您所见,唯一定义的请求元
我是 zeep 的新手。 我有以下效果很好: import zeep from zeep.cache import SqliteCache from zeep.transports import Tr
我需要通过 wsdl 使用 API,并且我正在尝试弄清楚 zeep 模块是如何工作的。该模块是使用“pip install”安装的,每次都显示相同的错误。 导入错误:无法从“zeep”导入名称“Cli
我有以下 python 代码来设置 SOAP 请求的 header : ebsheader = xsd.Element( '{http://ebs.health.ontario.ca/}EBS
我正在尝试让 zeep 打开一个 WSDL,该 WSDL 在名称的开头具有带点的绑定(bind),并收到 ValueError: Invalid tag name '.USXMLWSSoapBindi
我正在尝试使用此处发布的特别神秘的 WSDL SOAP 服务: https://api.business.govt.nz/registry/resource/_system/governance/ap
我必须在项目中使用 SOAP API。对于特定方法,我必须发送复杂类型。 这个复杂类型的声明如下:
我是一名优秀的程序员,十分优秀!