在Python Zeep中更改服务URL

eis*_*er9 6 python soap

我想使用Python Zeep SOAP客户端向Cisco CUCM发出SOAP调用.在思科WSDL文件中,服务定义为:

<service name="AXLAPIService">
    <port binding="s0:AXLAPIBinding" name="AXLPort">
        <soap:address location="https://CCMSERVERNAME:8443/axl/"/>
    </port>
</service>
Run Code Online (Sandbox Code Playgroud)

现在我想将"CCMSERVERNAME"更改为真实的内容,例如"192.168.250.10"而不更改WSDL.

但是从Docs我找不到任何改变它的东西.

我在这里找到了一个关于使用"Client.set_address()"更改URL的讨论,但这不再起作用了.

任何人都能给我一个提示吗?

编辑:有了mvt的帮助,我得到了它,对于任何有相同问题的人,使用此命令创建服务:

service = client.create_service("  {http://www.cisco.com/AXLAPIService/}AXLAPIBinding","https://192.168.250.10:8443/axl/")
Run Code Online (Sandbox Code Playgroud)

这是一个有效的SOAP调用示例:

phones = service.listPhone({'devicePoolName':'Default'},returnedTags={'name':'','model':''})
Run Code Online (Sandbox Code Playgroud)

返回列表中的设备:

SEPFFFFFFFFFFAA Cisco 7841
SEPAAAABBBB2222 Cisco 7841
Run Code Online (Sandbox Code Playgroud)

as *_* if 7

另一个快速破解可能是。

client.service._binding_options["address"] = your_url


Pel*_*lle 5

对于无法通过 Internet 访问的内部服务器上的端点,使用 ssh 到 localhost:8080 的端口转发端口 80 我制作了以下代码段,它复制服务绑定并将转换应用于绑定地址以创建新服务。

def get_service(client, translation):
    if translation:
        service_binding = client.service._binding.name
        service_address = client.service._binding_options['address']
        return client.create_service(
            service_binding,
            service_address.replace(*translation, 1))
    else:
        return client.service

# ssh port forwarded internal.example.com:80 to localhost:8080

client = zeep.Client(wsdl="localhost:8080/endpoint?WSDL")

# client.service now points to the unreachable url internal.example.com/endpoint

service = get_service(client=client, translation=('internal.example.com', 'localhost:8080'))

# service now points to localhost:8080/endpoint
Run Code Online (Sandbox Code Playgroud)