suds調用webserive的suds.TypeNotFound錯誤解決


一、問題概述

  任務中涉及到調用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


免責聲明!

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



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