相关疑难解决方法(0)

使用Python Zeep反思WSDL

我试图使用Zeep来描述给定WSDL中的操作和类型,以便程序知道操作名称,它们的参数名称,参数类型和参数属性.

此信息将用于动态生成给定WSDL的UI.

到目前为止我所获得的仅仅是操作和类型的字符串表示.使用与此答案中的代码类似的代码.

这是一个例子:

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())
Run Code Online (Sandbox Code Playgroud)

这给出了如下输出(为简洁起见缩短)

[...]

method : CartCreate
  input : MarketplaceDomain: xsd:string, AWSAccessKeyId: xsd:string, AssociateTag: xsd:string, Validate: xsd:string, XMLEscaping: …
Run Code Online (Sandbox Code Playgroud)

python soap wsdl soappy zeep

11
推荐指数
2
解决办法
6314
查看次数

标签 统计

python ×1

soap ×1

soappy ×1

wsdl ×1

zeep ×1