我有一个Python脚本,可以使用suds 0.4.1-3.el6通过SOAP接口与某些第三方软件一起使用。
在最近更新软件之前,一切正常。现在所有的脚本都像:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
import logging
from suds import WebFault
from suds.client import Client
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
client = Client("http://localhost:80/admin/soap/api3.wsdl")
#print client.location
#client.location = 'http://localhost:34012/'
print client
结束于:
Traceback (most recent call last):
File "print.py", line 18, in <module>
client = Client("http://localhost:80/admin/soap/api3.wsdl")
File "/usr/lib/python2.6/site-packages/suds/client.py", line 119, in __init__
sd = ServiceDefinition(self.wsdl, s)
File "/usr/lib/python2.6/site-packages/suds/servicedefinition.py", line 58, in __init__
self.paramtypes()
File "/usr/lib/python2.6/site-packages/suds/servicedefinition.py", line 137, in paramtypes
item = (pd[1], pd[1].resolve())
File "/usr/lib/python2.6/site-packages/suds/xsd/sxbasic.py", line 63, in resolve
raise TypeNotFound(qref)
suds.TypeNotFound: Type not found: '(soapDiscountAddons, http://www.w3.org/2001/XMLSchema, )'
软件支持说“我们的WSDL文件很好,请问suds开发人员”,所以我需要帮助来调查这个问题。
以前的工作档案:
https://dl.dropbox.com/u/4299326/py/20130225.wsdl/old/api3.wsdl
https://dl.dropbox.com/u/4299326/py/20130225.wsdl/old/encoding.xml
新的崩溃文件:
https://dl.dropbox.com/u/4299326/py/20130225.wsdl/new/api3.wsdl
https://dl.dropbox.com/u/4299326/py/20130225.wsdl/new/encoding.xml
答案 0 :(得分:3)
软件支持说“我们的WSDL文件很好,请问suds开发人员”
我不认为这是对的。显示Type not found: '(soapDiscountAddons, http://www.w3.org/2001/XMLSchema, )'
消息suds是正确的。
通过查看您的WSDL,soapDiscountAddons
位于urn:api3
命名空间中,因此您需要在使用它时提及它。问题出在这里:
<!-- operation response element -->
<element name="getDiscountAddonsResponse">
<complexType>
<sequence>
<element name="ret" type="soapDiscountAddons" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<!-- operation request element -->
<element name="insupdDiscountAddon">
<complexType>
<sequence>
<element name="val" type="soapDiscountAddons" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
</element>
由于您没有为类型添加前缀,因此使用的当前命名空间为http://www.w3.org/2001/XMLSchema
,而不是urn:api3
。 suds试图找到一个当然不存在的soapDiscountAddons@urn:api3
元素,而不是寻找类型所在的soapDiscountAddons@http://www.w3.org/2001/XMLSchema
。
这应该解决它:
<element name="getDiscountAddonsResponse">
<complexType>
<sequence>
<element name="ret" type="lbapi:soapDiscountAddons" minOccurs="1" maxOccurs="unbounded"/>
<!-- ^^^^^ you are missing this -->
</sequence>
</complexType>
</element>
<!-- operation request element -->
<element name="insupdDiscountAddon">
<complexType>
<sequence>
<element name="val" type="lbapi:soapDiscountAddons" minOccurs="1" maxOccurs="1"/>
<!-- ^^^^^ you are missing this -->
</sequence>
</complexType>
</element>