我正在尝试在Python中编写一个使用WSDL文件的简单SOAP客户端。我尝试了pysimplesoap和SUDS,这两种因各种原因而失败。
from pysimplesoap.client import SoapClient
wsdl = "http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl"
client = SoapClient(wsdl=wsdl)
print client
pysimplesoap客户端失败并显示AttributeError: Tag not found: service (No elements found)
from SOAPpy import WSDL
wsdlFile = "http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl"
server = WSDL.Proxy(wsdlFile)
SOAPpy客户端抛出IndexError: list index out of range
例外。
我是SOAP的新手,所以我猜我在某个地方犯了一个非常基本的错误。
答案 0 :(得分:0)
suds:
添加
<wsdl:service name="DeviceService">
<wsdl:port binding="tds:DeviceBinding" name="DevicePort">
<soap:address location="http://localhost/onvif/device_service/"/>
</wsdl:port>
</wsdl:service>
之间 和 在devicemgmt.wsdl文件的末尾。原来的wsdl没有定义服务,这就是为什么suds不开心的原因
剧本:
import suds
import os
SERVER_URL = 'http://<INSERT_YOUR_CAMERAS_IP_HERE>:80/device_service'
WSDL_URL='file:' + os.getcwd() + '/wsdl/devicemgmt.wsdl'
cli=suds.client.Client(WSDL_URL)
cli.set_options(location=SERVER_URL)
security = suds.wsse.Security()
token = suds.wsse.UsernameToken('<INSERT_YOUR_USERNAME>', '<INSERT_YOUR_PASSWORD>')
token.setnonce('<INSERT_YOUR_NONCE>') # token.setonce() didn't work for me
token.setcreated()
security.tokens.append(token)
cli.set_options(wsse=security)
res=cli.service.GetDeviceInformation()
print res
“print cli”不起作用,但没关系...... wsdl的位置是./wsdl/devicemgmt.wsdl,wsdl引用的文件放在同一位置(修复链接后)