Python3 webservice接口測(cè)試代碼詳解
一、使用python3做webervice接口測(cè)試的第三方庫(kù)選擇suds-jurko庫(kù),可以直接pip命令直接下載,也可以在pypi官網(wǎng)下載壓縮包進(jìn)行手動(dòng)安裝
二、安裝好后,導(dǎo)入Client:from suds.client import Client。發(fā)送一條請(qǐng)求
from suds.client import Client url = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl' client = Client(url) # 打印所有webservice接口信息 print(client)
但是會(huì)出現(xiàn)錯(cuò)誤:
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, )'
三、只需要過濾掉一下地址就可以了。導(dǎo)入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)
輸出結(jié)果:
(WeatherWebServiceSoap)
Methods (5):
getSupportCity(xs:string byProvinceName)
getSupportDataSet()
getSupportProvince()
getWeatherbyCityName(xs:string theCityName)
getWeatherbyCityNamePro(xs:string theCityName, xs:string theUserID)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
一道題學(xué)會(huì)Python函數(shù)中形參和實(shí)參
在Python編程中,函數(shù)的形參和實(shí)參是函數(shù)定義和調(diào)用的重要概念,本文主要介紹了一道題學(xué)會(huì)Python函數(shù)中形參和實(shí)參,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
對(duì)Python強(qiáng)大的可變參數(shù)傳遞機(jī)制詳解
今天小編就為大家分享一篇對(duì)Python強(qiáng)大的可變參數(shù)傳遞機(jī)制詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06
pytorch加載自己的圖片數(shù)據(jù)集的2種方法詳解
數(shù)據(jù)預(yù)處理在解決深度學(xué)習(xí)問題的過程中,往往需要花費(fèi)大量的時(shí)間和精力,下面這篇文章主要給大家介紹了關(guān)于pytorch加載自己的圖片數(shù)據(jù)集的2種方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06

