How to extract method using Suds in Python

怎甘沉沦 提交于 2019-12-05 00:19:05

问题


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. How can I achieve this?

from suds.client import client
url="name fo the url"
client=Client(url)
Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( Services ) tns="http://www.altoromutual.com/bank/ws/"
Prefixes (1)
ns0 = "http://www.altoromutual.com/bank/ws/"
Ports (2):
(ServicesSoap)
 Methods (3):
    GetUserAccounts(xs:int UserId, )
    IsValidUser(xs:string UserId, )
    TransferBalance(MoneyTransfer transDetails, )
 Types (4):
    AccountData
    ArrayOfAccountData
    MoneyTransfer
    Transaction
  (ServicesSoap12)
 Methods (3):
    GetUserAccounts(xs:int UserId, )
    IsValidUser(xs:string UserId, )
    TransferBalance(MoneyTransfer transDetails, )
 Types (4):
     AccountData
    ArrayOfAccountData
    MoneyTransfer
    Transaction 

回答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')" />)


来源:https://stackoverflow.com/questions/20903250/how-to-extract-method-using-suds-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!