对于python仅作为客户端调用webservice的情况,推荐使用suds库来完成,比起zsi,soapy之类,它可以说是相当轻量级,使用非常方便。
安装suds建议使用easy_insall来做。下面是官方的一些例子:
from suds.client import Client
url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url)
#查看该service提供的方法
print client
Suds - version: 0.3.3 build: (beta) R397-20081121
Service (WebServiceTestBeanService) tns="http://test.server.enterprise.rhq.org/"
Prefixes (1):
ns0 = "http://test.server.enterprise.rhq.org/"
Ports (1):
(Soap)
Methods:
addPerson(Person person, )
echo(xs:string arg0, )
getList(xs:string str, xs:int length, )
getPercentBodyFat(xs:string name, xs:int height, xs:int weight)
getPersonByName(Name name, )
hello()
testExceptions()
testListArg(xs:string[] list, )
testVoid()
updatePerson(AnotherPerson person, name name, )
Types (23):
Person
Name
Phone
AnotherPerson
1.简单参数调用
result = client.service.getPercentBodyFat('jeff', 68, 170)
print result
result = client.service.getPercentBodyFat(name='jeff', height=68, weight=170)
print result
#词典
d = dict(name='jeff', height=68, weight=170)
result = client.service.getPercentBodyFat(**d)
print result
You have 21% body fat.
2.复杂参数
person = client.factory.create('Person')
print person
(Person)=
{
phone = []
age = NONE
name(Name) =
{
last = NONE
first = NONE
}
}
#设置变量
phone = client.factory.create('Phone')
phone.npa = 202
phone.nxx = 555
phone.number = 1212
name = client.factory.create('Name')
name.first = 'Elmer'
name.last = 'Fudd'
person.name = name
person.age = 35
person.phone = [phone]
#或者
person.phone.append(phone)
try:
person_added = client.service.addPerson(person)
except WebFault, e:
print e
在0.3.8以上版本还提供了更简单的调用方式,完美的json
person = {}
#根据对象结构构造json
phone = {
'npa':202,
'nxx':555,
'number':1212,
}
name = {
'first':'Elmer',
'last':'Fudd'
}
person['name'] = name
person['age'] = 35
person['phone'] = [phone,]
try:
person_added = client.service.addPerson(person)
except WebFault, e:
print e
3.异常处理
client = client(url, faults=False)
result = client.service.addPerson(person)
print result
( 200, person ...)
更多可以查看官方文档:https://fedorahosted.org/suds/wiki/Documentation,里面还讲了soap头得安全认证,webservice cache等高级话题,有需要可以查看,都比较详细。
分享到:
相关推荐
今天小编就为大家分享一篇python使用suds调用webservice接口的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
webservice interface call by python
主要介绍了python suds访问webservice服务实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
使用suds这个第三方模块 from suds.client import Client url = 'http://ip:port/?wsdl' cilent=Client(url) print cilent 查看webservice接口的具体信息: 调用接口方法,通常 client.service.methodname 实际...
python-suds-0.4.1.tar.gz
suds-jurko-0.6.zip:python调用webservice的包,suds-jurko-0.6.zip:python调用webservice的包
离线安装包,亲测可用
一、使用python3做webervice接口测试的第三方库选择suds-jurko库,可以直接pip命令直接下载,也可以在pypi官网下载压缩包进行手动安装 二、安装好后,导入Client:from suds.client import Client。发送一条请求 ...
sudsssl运输 SUDS SOAP 库的健全 SSL 传输
一个python写的通用webservice client 涉及技术suds,wxpython,logging,base64
资源分类:Python库 所属语言:Python 资源全名:suds-ews-0.3.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
Python调用webservice接口包工具
Python3.x访问webservice所需要的第三方库。 具体安装方法请看我的新浪博客,ID My城
suds包,其中包括XMLSchema.xsd 和xml.xsd
Suds是LGPL许可下的Python轻量级基于SOAP的Web服务客户端(请参阅发行版中包含的LICENSE.txt文件)。 这是jurko分支的社区分支。 分叉的项目信息 项目站点 可以从以下网站下载官方版本: Github- PyPI- //pypi....
python写的一个通用webservice client 涉及suds,logging,threading,wxpython
NULL 博文链接:https://huangfang7891-gmail-com.iteye.com/blog/1893536