Skip to main content
 首页 » 编程设计

python之泡沫抛出错误 'type not found' 使用 SOAP 服务

2025年05月04日11三少

我正在使用 suds (0.4) 的 SOAP 网络服务. WSDL我正在使用抛出错误

>>> import uuid 
>>> from suds.client import Client 
>>> wsdl = 'https://toolkit.dnb.com/locked/resource/docs/TransactionAndMessageDefinition/ProductList.wsdl' 
>>> client = Client(wsdl)  

我正在使用的服务需要一个参数 productListRequest,这是一个复杂类型,您可以在其中放置 UserId、Password 和一个复杂类型产品列表输入。

我填写这些:

>>> productListRequest = client.factory.create('productListRequest') 
>>> productListRequest.UserId = 'myusername' 
>>> productListRequest.Password = 'mypassword' 
>>> productListRequest.TRNUID = uuid.uuid4() 
>>> ProductListInput = client.factory.create('ProductListInput') 
>>> ProductListInput.DnB_DUNS_Number = '' 
>>> ProductListInput.Product = 'Product Name' 
>>> ProductListInput.CountryCode = 'IT' 
>>> ProductListInput.TradeUp = '' 
>>> ProductListInput.Reason = '' 
>>> productListRequest.ProductListInput = ProductListInput 

但是每当我调用该服务时:

>>> print client.service.ws_ProductList(productListRequest) 

我得到 Type not found: 'ArrayOfUPD_FLDSItem'

我真的被困在这里了。我用谷歌搜索了这个错误 2 天,老实说我不知道​​该怎么办!也许对 WSDL 和 suds 有更深入了解的人可以提供帮助。

所以我的问题:

  • 我使用的这个 WSDL 是否定义正确? (如果定义正确,我会报告给 SOAP 水 维护者)

  • 如果此 WSDL 未正确定义,是否有解决方法(例如 suds 架构医生)在 suds 网站上修复它?

  • 是否有我应该使用的替代 Python 库?

请您参考如下方法:

Suds 目前是在 Python 中使用 WSDL 的最佳选择。不幸的是,WSDL 本身是如此复杂的一团糟,以至于很难利用它。

幸运的是,Suds 具有广泛的日志记录功能,您可以使用它来调试问题,这是解决问题的第一步。这个较早的问题回答了如何启用它:

How can I output what SUDs is generating/receiving?

但是,要给出类型错误的完整答案需要查看大量的日志输出和/或源代码,所以我建议您以某种方式尝试缩小问题范围。为了使问题最终可解决,示例(非工作)模式和 Python 代码会很好。

(错误可能暗示有一些子模式/外部模式定义/缺失,Suds 由于 X 原因无法加载)