【问题标题】:WSDL Type not found未找到 WSDL 类型
【发布时间】:2014-10-20 08:20:32
【问题描述】:

我正在尝试使用 suds for django 获得 WSDL 响应。但是我无缘无故地收到一个未找到类型的错误。

Type not found: 'ProfileInfo'

这就是我的 xml 的样子:

 <Profiles>
   <ProfileInfo>
     <Profile ProfileType="1">
       <Customer>
       </Customer>
     </Profile>
   </ProfileInfo>
 </Profiles>

suds 客户向我提供了 2 个对象:

ns0:ProfileType
ns0:ProfilesType

没有 ProfileInfo 对象。

这就是我所做的: 我创建了一个 ProfilesType 对象:

profiles = client.factory.create('ns0:ProfilesType')

这个对象看起来像这样:

(ProfilesType){
   ProfileInfo[] = <empty>
}

由于没有可以创建的 ProfileInfo 对象,我尝试了两种方法: 1. 将 ProfileType 对象附加到 ProfileInfo 中

profile = client.factory.create('ns0:ProfileType')
profiles.ProfileInfo.append(profile)

这会生成以下被服务器拒绝的 XML。

 <Profiles>
   <ProfileInfo>
     <Customer>
     </Customer>
   </ProfileInfo>
 </Profiles>

2.. 创建一个虚拟的 profileinfo 对象并为其添加 profiletype:

 profile_info = {"ProfileInfo": []}
 profile_info["ProfileInfo"].append(profile)
 profiles.ProfileInfo.append(profile_info)

这会引发错误“找不到类型:'ProfileInfo'”

我该怎么办?我一直在尝试各种组合,但似乎没有任何效果。

【问题讨论】:

  • 找到这个了吗?我得到同样的问题。所以如果你解决了它,请分享解决方案

标签: django wsdl suds


【解决方案1】:

我要去试试 suds 医生,可能会有帮助,请参阅:Suds: Type not found on response

这个答案让我走上了正轨。导入医生没有工作,但这样做了:

https://fedorahosted.org/suds/wiki/Documentation#FIXINGBROKENSCHEMAs

我打开模式,查看缺少的类型所指的位置,并找到了命名空间和位置,并在此处填写:

from suds.xsd.sxbasic import Import

ns = '<fill in the namespace for the missing type>'
schema_url  = '<fill in the url>'
Import.bind(ns, location)
# repeat this for all missing types
# and than create the client
client = Client(wsdl_url)
message= '%s' % client
# log the message, and this works for me!

【讨论】:

    【解决方案2】:

    我必须创建一个虚拟 ProfileInfo 对象。

    profile_info = {"Profile": []}
    profile_info["Profile"].append(profile)
    profiles = client.factory.create('ns0:ProfilesType')
    profiles.ProfileInfo.append(profile_info)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      相关资源
      最近更新 更多