【问题标题】:How to extract method using Suds in Python如何在 Python 中使用 Suds 提取方法
【发布时间】:2014-01-03 12:04:42
【问题描述】:

我想提取所有方法并想使用如何使用 python 进行自动化发送一些参数。

我只想要方法作为用户输入并将参数发送给方法。 我怎样才能做到这一点?

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 

【问题讨论】:

    标签: python-2.7 suds


    【解决方案1】:

    列出 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]
    

    然后调用方法本身:

    >>> response = client.service.GetCitiesByCountry(CountryName="France")
    

    注意:“Python Web Service Client Using SUDS and ServiceNow”提供了一些简单的示例。

    根据@kflaw 的评论,这是检索应该传递给方法的参数列表的方法:

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

    【讨论】:

    • 你怎么知道传递给方法的值应该采用什么格式,就像在你的例子中一样,你怎么知道值应该格式化为 CountryName='France' 而不仅仅是 '法国?
    • @kflaw 我已经更新了我的答案,以检索参数的名称和类型。
    • 谢谢!我还发现temp = str(client); 给了我一些关于类型和需要什么的额外信息。不幸的是,我仍然感到困惑,并认为我需要与开发该服务的人交谈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2011-02-09
    • 1970-01-01
    • 2013-11-03
    相关资源
    最近更新 更多