9-09 10 views
一、背景
最近在对接其它部门的平台,他们是用java写的webservice接口,在python环境中是用suds来实现的,关于suds pypi上有很多种我个人用下来比较喜欢suds-jurko
二、安装
我这里只写easy_install和pip的安装方式,喜欢源码的去自行到pypi下载然后解压,用python setup.py install就行
我个人的环境是CentOS7.5 , python3.6,以下以python3为例
2.1 easy_install
1 |
easy_install suds-jurko |
2.2 pip
1 |
pip install suds-jurko |
三、测试
3.1 调用
1 2 3 4 5 6 7 8 9 10 |
(cmdb) [root@009025000 ~]# ipython Python 3.6.6 (default, Jul 4 2018, 15:26:10) Type 'copyright', 'credits' or 'license' for more information IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: from suds.client import Client In [2]: headers={'Content-Type':'application/soap+xml;charset="UTF-8"'} In [3]: client=Client('http://192.168.15.106/services/HrmService?wsdl',headers=headers,faults=False,timeout=15) |
3.2 打印接口下的所有方法
会列出此接口下支持的所有的方法和方法支持的参数及类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
In [4]: print(client) Suds ( https://fedorahosted.org/suds/ ) version: 0.6 Service ( HrmService ) tns="http://localhost/services/HrmService" Prefixes (1) ns0 = "http://webservice.hrm.weaver" Ports (1): (HrmServiceHttpPort) Methods (1): getHrmSubcompanyInfo(xs:string in0) getHrmUserInfo(xs:string name, xs:int age, xs:string phone) Types (1): ns0:SubCompanyBean |
3.3 调用
如果每个参数都是必须传的,参数名可带可不带
1 2 3 |
In [5]: result=client.service.getHrmDepartmentInfo(in0='192.168.1.5') In [6]: print(result) |
3.4 传字典型参数
如果有多个参数,也支持直接传字典类型
1 2 3 4 5 |
In [7]: d=dict(name='Eric',age=17,phone='11111111111') In [8]: result=client.service.getHrmUserInfo(d) In [9]: print(result) |
如果想赏钱,可以用微信扫描下面的二维码,一来能刺激我写博客的欲望,二来好维护云主机的费用; 另外再次标注博客原地址 itnotebooks.com 感谢!
