本文介绍了如何在 Python 中使用 Suds 提取方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

from suds.client 导入客户端url="url 的名称"客户=客户(网址)Suds ( https://fedorahosted.org/suds/) 版本:0.4 GA 版本:R699-20100913服务(服务)tns="http://www.altoromutual.com/bank/ws/"前缀 (1)ns0 = "http://www.altoromutual.com/bank/ws/"端口 (2):(服务肥皂)方法(3):GetUserAccounts(xs:int UserId, )IsValidUser(xs:string UserId, )TransferBalance(MoneyTransfer transDetails, )类型 (4):账户数据帐户数据数组汇款交易(ServicesSoap12)方法(3):GetUserAccounts(xs:int UserId, )IsValidUser(xs:string UserId, )TransferBalance(MoneyTransfer transDetails, )类型 (4):账户数据帐户数据数组汇款交易
解决方案

要列出 WSDL 中所有可用的方法:

>>>从 suds.client 导入客户端>>>url_service = 'http://www.webservicex.net/globalweather.asmx?WSDL'>>>客户端 = 客户端(url_service)>>>list_of_methods = [client.wsdl.services[0].ports[0].methods 中的方法的方法]>>>打印 list_of_methods[GetWeather, GetCitiesByCountry]

然后调用方法本身:

>>>response = client.service.GetCitiesByCountry(CountryName="法国")

注意:使用 SUDS 和 ServiceNow 的 Python Web 服务客户端".

按照@kflaw 的评论,这是如何检索一个人应该传递给方法的参数列表:

>>>方法 = client.wsdl.services[0].ports[0].methods["GetCitiesByCountry"]>>>params = method.binding.input.param_defs(method)>>>打印参数[(CountryName, <Element:0x10a574490 name="CountryName" type="(u'string', u'http://www.w3.org/2001/XMLSchema')"/>)

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
解决方案

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

这篇关于如何在 Python 中使用 Suds 提取方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:22