python调用webservice接口的实现

yipeiwu_com6年前Python基础

使用suds这个第三方模块

from suds.client import Client
url = 'http://ip:port/?wsdl'
cilent=Client(url)
print cilent 

查看webservice接口的具体信息:

调用接口方法,通常 client.service.methodname

实际测试过程中遇到的坑:

1、tns 值为Localhost

之前查看接口信息时,未发现tns="http://Localhost:4567/Interface.wsdl",这个被设置成Localhost,导致通过接口调用时,只能在webservice接口本地服务器上才能调用成功,其他服务器调用时,接口中的方法都无法获取。大坑!

解决方法:修改webservice接口对应的wsdl文件 Interface.wsdl,将其中的Localhost改成具体ip即可。

2、接口方法名不符合python命名规范

比如上述的方法,无法直接这样调用

解决办法:python内置函数getattr 。 getattr(cilent.service,'ser-GetAreaID')('1')

3、接口方法传参

此方法为例

1、方法一:

soap_rep=getattr(soapService, 'ser-SetValue')(nSetFlag=1,nSystemID=1,nRecordNo=440002028,nTableNo=18,cValue='225',UserName='admin')

2、方法二:

soap_rep=getattr(soapService, 'ser-SetValue')(1,1,440002028,18,'225','admin') # 需要一一对应

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

django获取from表单multiple-select的value和id的方法

如下所示: <select id="host_list" name="host_list" multiple> {% for op in host_list %}...

使用urllib库的urlretrieve()方法下载网络文件到本地的方法

使用urllib库的urlretrieve()方法下载网络文件到本地的方法

概述 见源码 源码 # !/usr/bin/env python # -*- coding:utf-8 -*- """ 图片(文件)下载,核心方法是 urllib.urlre...

Python数据分析模块pandas用法详解

Python数据分析模块pandas用法详解

本文实例讲述了Python数据分析模块pandas用法。分享给大家供大家参考,具体如下: 一 介绍 pandas(Python Data Analysis Library)是基于num...

Python 串口读写的实现方法

Python 串口读写的实现方法

1.安装pyserial https://pypi.python.org/pypi/pyserial Doc:http://pythonhosted.org/pyserial/ 使用Py...

python安装pil库方法及代码

python安装pil库方法及代码

安装PIL 在Debian/Ubuntu Linux下直接通过apt安装: $ sudo apt-get install python-imaging Mac和其他版本的Linux...