zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    VMware12中CentOS7网络设置
    技术牛人
    PHP程序员如何突破成长瓶颈(php开发三到四年)
    php多线程
    go git 安装配置与使用 (windows 7 64bit)
    php内核和瓦力上线部署
    VM虚拟机下安装Centos7.0图文教程
    php结合redis实现高并发下的抢购、秒杀功能
    php foreach循环中unset后续的键值问题
    excle导入
  • 原文地址:https://www.cnblogs.com/elephanyu/p/9136556.html
Copyright © 2011-2022 走看看