【我理解的Python】处理webservices接口

总结我所理解的,整理过程的点点滴滴,只为回首往事时不因虚度年华而悔恨,不因碌碌无为而羞耻。

欢迎你来我的千聊平台,我们一起颠覆你的Python接口自动化测试

【目录】我所理解的Python

【我理解的Python】处理webservices接口_第1张图片

更新记录2018-7-17 16:10:27
1.Python3使用suds时,需要 pip install suds-py3
2.如果提示"no module name ‘client’",需要额外安装 pip install client

【样例解释】

# -*- coding: utf-8 -*-
'''
1.发送webservices协议接口请求并获取数据
'''
from suds.client import Client
class OpWebservices(object):
    #定义初始化数据,分别是接口地址?wsdl,方法名,接口参数(字典形式)
    def __init__(self,url_interface,params_interface):
        self.url=url_interface
        self.params=params_interface
    #定义处理webservices协议接口请求
    def handle_wbs(self):
        client = Client(self.url)  # Client里面直接放访问的URL,可以生成一个webservice对象
        #print(client)  # 打印所webservice里面的所有接口方法名称
        result = client.service.toTraditionalChinese(**self.params)
        response = str(client.last_received())  # 保存返回报文,返回的也是一个实例,xml形式的
        return response,result

test_Opwbs=OpWebservices(url_interface="http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl",
params_interface={'sText':u'台湾'})
r_response,r_result=test_Opwbs.handle_wbs()
print(r_response)
print(r_result)
#执行结果是:


   
      
         臺灣
      
   

臺灣

【下一步优化】

1、调用client.service.方法名,该方法名是否可以作为参数传入,否则N多接口要写N个处理方法,或者这个整体作为接口请求
2、对返回结果xml的处理

作者简介:
1、6年软件测试经验;2、擅长接口手工测试及自动化测试,UI自动化,Django 框架;3、自编自导自演了一套基于 Python + Django + MySQL 的自动化测试平台;

想更深入的了解,欢迎来我的千聊平台,我们一起颠覆你的Python接口自动化测试

【目录】我所理解的Python

你可能感兴趣的:(【我理解的Python】处理webservices接口)