0

I'm attempting to write a simple SOAP client in Python that consumes a WSDL file. I've tried pysimplesoap and SUDS and both of these fail for various reasons.

from pysimplesoap.client import SoapClient

wsdl = "http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl"
client = SoapClient(wsdl=wsdl)

print client

The pysimplesoap client fails with 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)

The SOAPpy client throws an IndexError: list index out of range exception.

I a total newbie to SOAP, so I'm guessing that I've made a very basic error somewhere.

CadentOrange
  • 3,263
  • 1
  • 34
  • 52

1 Answers1

0

With suds:

Add

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

between and at the end of devicemgmt.wsdl file. The original wsdl didn't have the service defined and this was the reason why suds was unhappy

The script:

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" doesn't work but never mind... Location of wsdl is ./wsdl/devicemgmt.wsdl and files referred from the wsdl were placed in the same location (after fixing the links)

Adam K
  • 1
  • Following your post, I've downloaded the devicemgmt.wsdl file and edited it to include the `` fragment posted and I've placed it at the end of the file, just before ``. I'm now getting the error `Exception: No services defined`. I think this is making progress, slowly... – CadentOrange Feb 07 '14 at 14:51
  • So very close. I've edited the devicemgmt.wsdl so that onvif.xsd comes directly from the ONVIF website. I'm now getting a 502 "bad gateway" error. – CadentOrange Feb 07 '14 at 16:08