2017-02-20 91 views
1

我正在使用ONVIF協議實現應用程序。有一個我必須使用的WSDL文件https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl。但是,有必要定義默認服務,添加以下代碼到WSDL文件:ONVIF - Python + ZEEP:create_service無法正常工作

<wsdl:service name="DeviceService"> 
    <wsdl:port name="DevicePort" binding="tds:DeviceBinding"> 
     <soap:address location="http://ip_address/onvif/device_service"/> 
    </wsdl:port> 
</wsdl:service> 

但它不是可能的,因爲以下幾點:

  1. 將節點添加到WSDL文件中,你必須下載WSDL文件(這不是一個真正的問題,因爲我現在下載文件的性能 - 現在)
  2. 應用程序應該與各種網絡中的許多IP攝像機進行通信,因此無法定義行:<soap:address location="http://ip/onvif/device_service"/>

所以我一直在尋找一些解決方案,我發現它ZEEP文檔(http://docs.python-zeep.org/en/master/client.html#creating-new-serviceproxy-objects),其中出自於:

There are situations where you either need to change the SOAP address from the one which is defined within the WSDL or the WSDL doesn’t define any service elements.

所以我試圖調用此:

client = Client(
    wsdl = '/path/to/local/wsdl_file.wsdl', 
    wsse = self.InitSecurity(), 
    service_name = 'DeviceService', 
    port_name = 'DevicePort' 
) 

service = client.create_service(
    '{http://www.onvif.org/ver10/device/wsdl}DeviceBinding', 
    'http://ip_address/onvif/device_service' 
) 

但是當我運行腳本時,拋出以下異常:

ValueError: There is no default service defined. This is usually due to missing wsdl:service definitions in the WSDL

而當我直接修改WSDL文件(將節點ab奧夫),一切正常。

有什麼想法嗎?我打了一陣子,所以我需要踢一點點。

謝謝。

回答

1

service = client.create_service()應該可以工作(同樣的wsdl參見https://github.com/mvantellingen/python-zeep/issues/106)。

您使用的是創建服務對象的後續調用(如service.Operation()而不是客戶端?

+0

不幸的是,它並沒有爲我工作,但我希望:-(。你的答案後,我發現我的版本Zeep(0.21.0),我認爲這可能是因爲它,但根據發佈日期,它應該包含工作的create_service()方法,儘管如此,我已經更新到1.1.0,但仍然無法工作 - 同樣的例外是拋出(沒有默認的服務定義)。「隨後的調用」,我想我 - 我打電話client.service.Operation(),是否可以嗎?我上面寫的代碼段是正確的(我的意思是代碼client和create_service)? – Honza

+0

沒有,這就是它實際上給你錯誤的原因。client.service對象是默認的mappi NG。既然你用create_service創建了一個新的,你需要使用它。所以my_service = client.create_service(..); my_service.operaton() – mvantellingen

+0

所以,你的建議就是答案 - 但要結合特定版本的Zeep。這有點奇怪,但是當我安裝Zeep版本從0.21.0到0.24.0時,它完美地工作,當我安裝版本0.26.0和0.27.0的Zeep時,它只是X請求中的一個(在其他X中-1請求它拋出一個我將進一步描述的異常),當我安裝版本1.0.0和1.1.0的Zeep時,每次都拋出一個異常:「http.client.RemoteDisconnected:遠程結束時沒有響應的關閉連接」。所以我試圖升級每個依賴項,但它不會幫助。再次感謝你。 – Honza