Python3 webservice接口测试代码详解

作者:vevian 时间:2022-10-21 18:54:51 

一、使用python3做webervice接口测试的第三方库选择suds-jurko库,可以直接pip命令直接下载,也可以在pypi官网下载压缩包进行手动安装

二、安装好后,导入Client:from suds.client import Client。发送一条请求


from suds.client import Client
url = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl'
client = Client(url)
# 打印所有webservice接口信息
print(client)

但是会出现错误:


Traceback (most recent call last):
File "E:/PycharmProjects/lianxiUItestSelenium/***.py", line 53, in <module>
 client = Client('http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl')
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\client.py", line 115, in __init__
 self.wsdl = reader.open(url)
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\reader.py", line 150, in open
 d = self.fn(url, self.options)
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\wsdl.py", line 159, in __init__
 self.build_schema()
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\wsdl.py", line 220, in build_schema
 self.schema = container.load(self.options)
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\xsd\schema.py", line 94, in load
 child.dereference()
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\xsd\schema.py", line 319, in dereference
 midx, deps = x.dependencies()
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\xsd\sxbasic.py", line 437, in dependencies
 e = self.__deref()
File "E:\PycharmProjects\lianxiUItestSelenium\venv\lib\site-packages\suds\xsd\sxbasic.py", line 483, in __deref
 raise TypeNotFound(self.ref)
suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'

三、只需要过滤掉一下地址就可以了。导入ImportDoctor和Import就可以


from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import

imp = Import('http://www.w3.org/2001/XMLSchema',location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://WebXml.com.cn/')
doctor = ImportDoctor(imp)
client = Client('http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl',doctor=doctor)
print(client)

输出结果:


(WeatherWebServiceSoap)
 Methods (5):
   getSupportCity(xs:string byProvinceName)
   getSupportDataSet()
   getSupportProvince()
   getWeatherbyCityName(xs:string theCityName)
   getWeatherbyCityNamePro(xs:string theCityName, xs:string theUserID)

来源:https://www.cnblogs.com/vevian/p/11518943.html

标签:python,web,service,接口,测试
0
投稿

猜你喜欢

  • mysql增量备份及断点恢复脚本实例

    2024-01-27 04:54:34
  • python实现可下载音乐的音乐播放器

    2023-04-26 09:01:52
  • Python使用正则匹配实现抓图代码分享

    2021-09-06 10:47:28
  • ORACLE ORA-01653: unable to extend table 的错误处理方案(oracle报错)

    2024-01-15 12:24:10
  • Python调用飞书发送消息的示例

    2022-10-20 14:21:23
  • 09七夕节各大搜索引擎LOGO欣赏

    2009-08-27 15:34:00
  • 谨慎使用PHP的引用原因分析

    2023-09-09 10:37:13
  • js实现复选框的全选和取消全选效果

    2024-05-02 17:40:02
  • Oracle常见错误代码的分析与解决

    2024-01-14 20:28:51
  • struts2.3.24+spring4.1.6+hibernate4.3.11+mysql5.5.25开发环境搭建图文教程

    2024-01-18 04:21:31
  • 如何批量消除网页超级链接上的“虚线框”

    2008-10-15 12:55:00
  • IE6,7下实现white-space:pre-wrap;

    2009-12-31 18:30:00
  • Python3读取和写入excel表格数据的示例代码

    2022-01-21 10:33:55
  • Python+Selenium自动化实现分页(pagination)处理

    2022-02-23 20:09:52
  • Vue + Node.js + MongoDB图片上传组件实现图片预览和删除功能详解

    2024-05-10 14:14:56
  • js放大镜放大图片效果

    2024-04-30 08:51:38
  • MySQL连接及基本信息查看命令汇总

    2024-01-24 10:47:40
  • python jupyter入门教程

    2022-08-19 20:42:04
  • Python Opencv基于透视变换的图像矫正

    2022-03-13 16:47:14
  • python实现三壶谜题的示例详解

    2021-12-09 19:56:15
  • asp之家 网络编程 m.aspxhome.com