Python/Suds:找不到类型:'xs:complexType

10 投票
1 回答
14129 浏览
提问于 2025-04-15 13:52

我有一个简单的Python测试脚本,它使用Suds来调用一个SOAP网络服务(这个服务是用ASP.net写的):

from suds.client import Client

url = 'http://someURL.asmx?WSDL'

client = Client( url )

result = client.service.GetPackageDetails( "MyPackage"  )

print result

当我运行这个测试脚本时,出现了以下错误(因为代码比较长,所以用了代码标记):

No handlers could be found for logger "suds.bindings.unmarshaller"
Traceback (most recent call last):
  File "sudsTest.py", line 9, in <module>
    result = client.service.GetPackageDetails( "t3db"  )
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 240, in __call__
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 379, in call
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 240, in __call__
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 422, in call
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 480, in invoke
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 505, in send
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 537, in succeeded
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/binding.py", line 149, in get_reply
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 303, in process
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 88, in process
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 104, in append
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 181, in append_children
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 104, in append
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 181, in append_children
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 104, in append
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 181, in append_children
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 102, in append
  File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 324, in start
suds.TypeNotFound: Type not found: 'xs:complexType'

查看WSDL文件头部的源代码(为了适应格式进行了重新排版):

<?xml version="1.0" encoding="utf-8" ?> 
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:s="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:tns="http://http://someInternalURL/webservices.asmx" 
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
targetNamespace="http://someURL.asmx" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

根据输出的最后一行,我猜测:

suds.TypeNotFound: Type not found: 'xs:complexType'

我需要使用Suds的doctor类来修复模式,但作为一个SOAP新手,我不知道在我的情况下具体需要修复什么。这里有没有人有使用Suds修复/纠正模式的经验?

1 个回答

14

Ewall的资源非常不错。如果你在suds的跟踪票据中搜索一下,你会发现其他人也遇到过和你类似的问题,不过他们使用的对象类型不同。通过这些例子和他们如何导入命名空间,你可以学到很多东西。

问题在于你的WSDL文件中包含了一个模式定义,它引用了(...),但没有正确导入"http://schemas.xmlsoap.org/soap/encoding/"这个命名空间(以及相关的模式)。这个模式可以通过运行时使用schema ImportDoctor来修复,具体讨论可以参考这里:https://fedorahosted.org/suds/wiki/Documentation#FIXINGBROKENSCHEMAs

这是一个相当常见的问题。

一个常被提到但没有被导入的模式是SOAP第5节的编码模式。现在可以通过以下方式来修复:

(以上的强调是我自己的).

你可以尝试这些文档提供的代码,添加你WSDL中出现的命名空间。这可能需要你反复尝试。

imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
# Below is your targetNamespace presented in WSDL. Remember
# that you can add more namespaces by appending more imp.filter.add
imp.filter.add('http://someURL.asmx') 
doctor = ImportDoctor(imp) 
client = Client(url, doctor=doctor)

你没有提供你正在使用的WSDL,我想你有自己的理由不想给我们看……所以我觉得你需要自己尝试这些可能性。祝你好运!

撰写回答