2017-02-14 41 views
2

我想使用Python Zeep SOAP客戶端向思科CUCM發出SOAP調用。 在Cisco WSDL文件是服務definded:在Python中更改服務URL Zeep

<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 

回答

0

對於內部服務器上的端點,在互聯網上不可達,端口轉發端口80使用SSH爲localhost: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