Skip to main content
 首页 » 编程设计

python之使用 Suds 的端口类型异常

2024年11月01日9rubylouvre

我正在尝试使用以下代码使用 Python Suds 连接到 Aramex 航运 SOAP API:

import suds 
from suds.client import Client 
client = Client('file:///home/test/test_wsdl_aramex/shipments-tracking-api-wsdl.wsdl',cache=None) 

但是启动后,出现如下异常:

>     raise Exception("portType '%s', not-found" % self.type) 
Exception: portType 'i0:Service_dd1_0', not-found 

可以找到 WSDL 文件源 here .

请您参考如下方法:

错误在这里:

<wsdl:binding type="i0:Service_1_0" name="BasicHttpBinding_Service_1_0"> 

和

The binding element has two attributes - name and type.

The name attribute (you can use any name you want) defines the name of the binding, and the type attribute points to the port for the binding, in this case the "glossaryTerms" port.

所以解析器找不到端口 type="i0:Service_1_0",在这个 wsdl 文件中有两个端口定义:

<wsdl:portType name="Service_1_0"> 
    <wsdl:operation name="TrackShipments"> 
      <wsdl:input name="ShipmentTrackingRequest" message="tns:ShipmentTrackingRequest" wsaw:Action="http://ws.aramex.net/ShippingAPI/v1/Service_1_0/TrackShipments"/> 
      <wsdl:output name="ShipmentTrackingResponse" message="tns:ShipmentTrackingResponse" wsaw:Action="http://ws.aramex.net/ShippingAPI/v1/Service_1_0/TrackShipmentsResponse"/> 
    </wsdl:operation> 
  </wsdl:portType> 
  <wsdl:service name="Service_1_0"> 
    <wsdl:port name="BasicHttpBinding_Service_1_0" binding="i0:BasicHttpBinding_Service_1_0"> 
      <soap:address location="http://ws.aramex.net/shippingapi/tracking/service_1_0.svc"/> 
    </wsdl:port> 
  </wsdl:service> 

所以现在您知道出了什么问题(更改 wsdl:binding 中的类型),并且您无法通过验证。