How To Extract Method Using Suds In Python
I want to extract all the methods and want to send some parameters using how can I do automation using python. I want only methods as user input and send parameters to the method.
Solution 1:
To list all the methods available in the WSDL:
>>> from suds.client import Client
>>> url_service = 'http://www.webservicex.net/globalweather.asmx?WSDL'
>>> client = Client(url_service)
>>> list_of_methods = [method for method in client.wsdl.services[0].ports[0].methods]
>>> print list_of_methods
[GetWeather, GetCitiesByCountry]
Then to call the method itself:
>>> response = client.service.GetCitiesByCountry(CountryName="France")
Note: Some simple examples are available at "Python Web Service Client Using SUDS and ServiceNow".
Following @kflaw's comment, this is how to retrieve the list of parameters that one's should pass to a method:
>>> method = client.wsdl.services[0].ports[0].methods["GetCitiesByCountry"]
>>> params = method.binding.input.param_defs(method)
>>> print params
[(CountryName, <Element:0x10a574490 name="CountryName" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />)
Post a Comment for "How To Extract Method Using Suds In Python"