web services 接口调用
1、安装suds-jurko: pip install suds-jurko
2、网站地址:http://www.webxml.com.cn/zh_cn/web_services.aspx
from suds.client import Client #号码归属地查询 url="http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl" client = Client(url) print(client)
输出:
Suds ( https://fedorahosted.org/suds/ ) version: 0.6 Service ( MobileCodeWS ) tns="http://WebXml.com.cn/" Prefixes (1) ns0 = "http://WebXml.com.cn/" Ports (2): (MobileCodeWSSoap) Methods (2): getDatabaseInfo() getMobileCodeInfo(xs:string mobileCode, xs:string userID) Types (1): ArrayOfString (MobileCodeWSSoap12) Methods (2): getDatabaseInfo() getMobileCodeInfo(xs:string mobileCode, xs:string userID) Types (1): ArrayOfString
根据输出可以了解到查询手机号码归属地的方法:getMobileCodeInfo()
from suds.client import Client #号码归属地查询 url="http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl" client = Client(url) res = client.service.getMobileCodeInfo("151*****") print(res)
输出:
手机号码错误 http://www.webxml.com.cn
二、查询天气:
from suds.client import Client url = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl" client=Client(url) print(client)
输出:
Traceback (most recent call last): File "E:/python/TestBaidu.py", line 4, in <module> client=Client(url) File "E:\python\lib\site-packages\suds\client.py", line 115, in __init__ self.wsdl = reader.open(url) File "E:\python\lib\site-packages\suds\reader.py", line 150, in open d = self.fn(url, self.options) File "E:\python\lib\site-packages\suds\wsdl.py", line 159, in __init__ self.build_schema() File "E:\python\lib\site-packages\suds\wsdl.py", line 220, in build_schema self.schema = container.load(self.options) File "E:\python\lib\site-packages\suds\xsd\schema.py", line 94, in load child.dereference() File "E:\python\lib\site-packages\suds\xsd\schema.py", line 319, in dereference midx, deps = x.dependencies() File "E:\python\lib\site-packages\suds\xsd\sxbasic.py", line 437, in dependencies e = self.__deref() File "E:\python\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, )'
根据错误信息修改代码:
from suds.client import Client from suds.xsd.doctor import ImportDoctor, Import url="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl" imp = Import('http://www.w3.org/2001/XMLSchema', location='http://www.w3.org/2001/XMLSchema.xsd') imp.filter.add('http://WebXml.com.cn/') client = Client(url,plugins=[ImportDoctor(imp)]) res = client.service.getWeather("成都") print(res)
(ArrayOfString){ string[] = "四川 成都", "成都", "1117", "2020/10/04 22:24:54", "今日天气实况:气温:16℃;风向/风力:北风 2级;湿度:89%", "紫外线强度:最弱。",