使用python suds访问WSDL服务时出现TypeNotFound: ArrayOfint错误
找不到类型: '(ArrayOfint, http://schemas.microsoft.com/2003/10/Serialization/Arrays, )' 这是suds解析器抛出的错误。 在...2003/10/Serialization/Arrays中定义了ArrayOfInt,所以我猜是因为Linux对大小写敏感导致的问题。 有没有什么办法可以解决这个问题呢?
from suds.client import Client
c = Client("https://developer-api.affili.net/V2.0/Logon.svc?wsdl")
以前是返回
Type not found: '(ArrayOfint, http://schemas.microsoft.com/2003/10/Serialization/Arrays, )'
但现在过了几天我连这个都收不到了,而是收到了一个
TypeNotFound: Type not found: '(Logon, http://affilinet.framework.webservices/types, )'
1 个回答
听起来你的 WSDL 文件有问题。你需要使用 SUDS 提供的 ImportDoctor
工具。这个工具可以帮助 Client
构造器使用在 http://schemas.microsoft.com/2003/10/Serialization/Arrays
找到的 ArrayOfint
类型。
我以前在处理其他服务时也做过类似的事情,但因为我看不到你的 WSDL 文件或代码,所以这只是我对如何修复它的最佳猜测,因为我无法自己测试:
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
# Obviously I made this up
wsdl_url = 'http://whatever/path/to/wsdl'
# Fix missing types with ImportDoctor
schema_url = 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
schema_import = Import(schema_url)
schema_doctor = ImportDoctor(schema_import)
# Pass doctor to Client
client = Client(url=wsdl_url, doctor=schema_doctor)
值得注意的是,网址 http://schemas.microsoft.com/2003/10/Serialization/Arrays 实际上是无效的(返回 404 错误),所以我不太确定这个网址是否正确。不过我相信我至少是在给你指引正确的方向。
根据你最近的评论进行编辑(2010-10-05):
使用你提供的这个网址 https://developer-api.affili.net/V2.0/Logon.svc?wsdl
,我成功创建了一个客户端。我必须使用 ImportDoctor
,因为它抛出了以下错误:
TypeNotFound: Type not found: '(Logon, http://affilinet.framework.webservices/types, )'
所以我使用了以下代码,成功得到了一个客户端对象:
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
wsdl_url = 'https://developer-api.affili.net/V2.0/Logon.svc?wsdl'
schema_url = 'http://affilinet.framework.webservices/types'
schema_import = Import(schema_url)
schema_doctor = ImportDoctor(schema_import)
client = Client(url=wsdl_url, doctor=schema_doctor)
打印客户端对象显示如下内容:
Suds ( https://fedorahosted.org/suds/ ) 版本:0.3.9 GA 构建:R659-20100219
Service ( Authentication ) tns="http://affilinet.framework.webservices/Svc"
Prefixes (5)
ns0 = "http://affilinet.framework.webservices/types"
ns1 = "http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF"
ns2 = "http://schemas.microsoft.com/2003/10/Serialization/"
ns3 = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"
ns4 = "http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation"
Ports (1):
(DefaultEndpointLogon)
Methods (2):
GetIdentifierExpiration(xs:string CredentialToken, )
Logon(xs:string Username, xs:string Password, ns0:WebServiceTypes WebServiceType, ns0:TokenDeveloperDetails DeveloperSettings, ns0:TokenApplicationDetails ApplicationSettings, )
Types (12):
ns3:ArrayOfKeyValueOfstringstring
ns1:ArrayOfValidationDetail
ns0:Logon
ns0:TokenApplicationDetails
ns0:TokenDeveloperDetails
ns1:ValidationDetail
ns4:ValidationFault
ns0:WebServiceTypes
ns0:affilinetWebserviceFault
ns2:char
ns2:duration
ns2:guid
在你可以使用 client.service.Logon()
之前,你需要满足该方法所需的类型签名。你需要使用 client.factory.create()
创建各种类型的对象(例如 client.factory.create('ns0:WebServiceTypes')
),并将这些对象与用户名/密码一起传递。