一、问题概述
任务中涉及到调用webservice服务,便使用suds写公共的webservice调用客户端,出现有的调用正常,有的调用异常,很奇怪,google才找到真正的解决方案,特此记录。
常见公共开发的webservice,用于测试客户端:https://blog.csdn.net/yixiaoping/article/details/16877623(仅部分可使用)
二、问题详情
调用手机号webservice服务时正常
1 # coding:utf-8 2 from suds.client import Client 3 4 if __name__ == '__main__': 5 client = Client('http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl') 6 print client.service.getMobileCodeInfo('15116020790', '') 7 8 ## result 9 15116020790:湖南 株洲 湖南移动全球通卡
调用天气webservice时出现如下异常
1 # coding: utf-8 2 from suds.client import Client 3 4 if __name__ == '__main__': 5 client = Client('http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl') 6 print client 7 8 ## result 9 File "pakages/suds/xsd/sxbasic.py", line 422, in dependencies 10 raise TypeNotFound(self.ref) 11 suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
三、解决方式
过滤掉一个地址
1 # coding: utf-8 2 from suds.client import Client 3 from suds.xsd.doctor import ImportDoctor, Import 4 5 if __name__ == '__main__': 6 imp = Import('http://www.w3.org/2001/XMLSchema', 7 location='http://www.w3.org/2001/XMLSchema.xsd') 8 imp.filter.add('http://WebXml.com.cn/') 9 doctor = ImportDoctor(imp) 10 client = Client('http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl', doctor=doctor) 11 # print client 12 print client.service.getWeatherbyCityName(u'上海') 13 14 ## result 15 (ArrayOfString){ 16 string[] = 17 "直辖市", 18 "上海", 19 ..., 20 "今日天气实况:气温:23℃;风向/风力:静风 0级;湿度:77%;紫外线强度:弱。空气质量:中。", ... 21 }
参考:
https://stackoverflow.com/questions/4719854/soap-suds-and-the-dreaded-schema-type-not-found-error
https://bitbucket.org/jurko/suds/issues/20/typenotfound-schema