python使用suds来调用webservice
对于python仅作为客户端调用webservice的情况,推荐使用suds库来完成,比起zsi,soapy之类,它可以说是相当轻量级,使用非常方便。
安装suds建议使用easy_insall来做。下面是官方的一些例子:
Python代码
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.简单参数调用
Python代码 ![]()
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.复杂参数
Java代码 ![]()
person = client.factory.create('Person')
print person
Java代码
(Person)=
{
phone = []
age = NONE
name(Name) =
{
last = NONE
first = NONE
}
}
#设置变量
Java代码 ![]()
phone = client.factory.create('Phone')
phone.npa = 202
phone.nxx = 555
phone.number = 1212
Python代码
name = client.factory.create('Name')
name.first = 'Elmer'
name.last = 'Fudd'
Python代码 ![]()
person.name = name
person.age = 35
person.phone = [phone] #或者
person.phone.append(phone)
Java代码 ![]()
try:
person_added = client.service.addPerson(person)
except WebFault, e:
print e
在0.3.8以上版本还提供了更简单的调用方式,完美的json![]()
Python代码
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.异常处理
Python代码 ![]()
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的更多相关文章
- Python之Suds库调用WCF时复杂参数序列化
今天主要做自动化测技术支持工作,最近一直在做接口自动化这块,前些天在研究将web页面模拟http进行接口自动化,这周杭州那边想测试WCF服务,所以这两天一直在探索.遇到的第一个问题就是服务参数传参序列 ...
- Python之Suds库调用WCF实现复杂参数序列化
今年主要做自动化测技术支持工作,最近一直在做接口自动化这块,前些天在研究将web页面模拟http进行接口自动化,这周杭州那边想测试WCF服务,所以这两天一直在探索.遇到的第一个问题就是服务参数传参序列 ...
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
- Python调用Webservice
使用Python调用webservice 推荐使用 suds包 该包一般在Python2.x python3各种麻烦 略过 实例 import suds # webservice url url ...
- python openpyxl、RESTful、Webservice接口 基础知识
最近 在做接口测试的时候,遇到如下问题:如何通过数据驱动去做批量接口测试呢,我们的测试数据放在哪里去维护?下面整理出相关点,供大家参考 1.如何维护接口测试数据:放在excel文件中,通过python ...
- 一个简单的webservice的demo(下)winform异步调用webservice
绕了一大圈,又开始接触winform的项目来了,虽然很小吧.写一个winform的异步调用webservice的demo,还是简单的. 一个简单的Webservice的demo,简单模拟服务 一个简单 ...
- 调用webservice进行身份验证
因为同事说在调用webservice的时候会弹出身份验证的窗口,直接调用会返回401,原因是站点部署的时候设置了身份验证(账号名称自己配置).因而在调用的时候需要加入身份验证的凭证. 至于如何获取身份 ...
- java接口调用——webservice就是一个RPC而已
很多新手一听到接口就蒙逼,不知道接口是什么!其实接口就是RPC,通过远程访问别的程序提供的方法,然后获得该方法执行的接口,而不需要在本地执行该方法.就是本地方法调用的升级版而已,我明天会上一篇如何通过 ...
- Android调用WebService
这两天给老师做地铁app的demo,与后台的交互要用WebService,还挺麻烦的.所以想写点,希望有用. Web Services(Web服务)是一个用于支持网络间不同机器互操作的软件系统,它是一 ...
随机推荐
- thinkphp 操作绑定到类
定义 ThinkPHP3.2版本提供了把每个操作方法定位到一个类的功能,可以让你的开发工作更细化,可以设置参数ACTION_BIND_CLASS,例如: 'ACTION_BIND_CLASS' =&g ...
- [BJOI 2018]染色
题意:求01成立. 并查集维护,记录一个变量判断决策. #include<bits/stdc++.h> using namespace std; #define int long long ...
- Entity Framework Code First使用者的福音 --- EF Power Tool使用记之二(问题探究)
转:http://www.cnblogs.com/LingzhiSun/archive/2011/06/13/EFPowerTool_2.html 上次为大家介绍EF Power Tool之后,不 ...
- python环境变量配置 - CSDN博客
一.下载: 1.官网下载python3.0系列(https://www.python.org/) 2.下载后图标为: 二.安装: Window下: 1.安装路径: 默认安装路径:C:\python35 ...
- VMware Workstation 10 配置Ubuntu环境
分享到 一键分享 QQ空间 新浪微博 百度云收藏 人人网 腾讯微博 百度相册 开心网 腾讯朋友 百度贴吧 豆瓣网 搜狐微博 百度新首页 QQ好友 和讯微博 更多... 百度分享 VMware Work ...
- easyui combotree的使用示例
一.View: 1.定义输入控件 <input id="ParentId" name="ParentId"> 2.绑定combotree $('#P ...
- lxml etree对存在的xml添加新节点,新节点没有排版格式化
新添加的时候如果不做处理,是这个样子 要在解析xml加上 parser = etree.XMLParser(remove_blank_text=True)xml = etree.parse(major ...
- JavaScript特效源码(3、菜单特效)
1.左键点击显示菜单 左键弹出式菜单[推荐][修改显示的文字及链接即可][共2步] ====1.将以下代码加入HEML的<head></head>之间: <style t ...
- UVA - 11327
UVA - 11327https://vjudge.net/problem/28358/origin求欧拉函数的前缀和,二分查找到那个位置,再从它开始暴力gcd找 #include <iostr ...
- bzoj1913: [Apio2010]signaling 信号覆盖
传送门 题解传送门 //Achen #include<algorithm> #include<iostream> #include<cstring> #includ ...