在Python Zeep中更改服务URL

2024-05-20 20:46:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用Python Zeep SOAP客户机向Cisco CUCM进行SOAP调用。 在Cisco WSDL文件中定义了服务:

<service name="AXLAPIService">
    <port binding="s0:AXLAPIBinding" name="AXLPort">
        <soap:address location="https://CCMSERVERNAME:8443/axl/"/>
    </port>
</service>

现在我想将“CCMSERVERNAME”更改为真实的名称,比如“192.168.250.10”,而不更改WSDL。

但从医生那里我找不到任何改变的东西。

我在这里找到了一个关于用“Client.set_address()”更改URL的讨论,但这不再有效。

有人能给我个提示吗?

编辑: 在mvt的帮助下,我明白了,对于有同样问题的任何人,使用以下命令创建服务:

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

下面是一个来自工作的SOAP调用的示例:

phones = service.listPhone({'devicePoolName':'Default'},returnedTags={'name':'','model':''})

返回列表中的设备:

SEPFFFFFFFFFFAA Cisco 7841
SEPAAAABBBB2222 Cisco 7841

Tags: 文件namehttps客户机portaddressservicecisco
2条回答

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

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

相关问题 更多 >