python3接口測試之webservice接口測試第三方庫選擇及新手問題


一、使用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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM