我在将suds用于WSDL时遇到问题。我正在用jurko-suds

>>> print(suds.version)
<module 'suds.version' from 'C:\Python27\lib\site-packages\suds_jurko-0.6-py2.7.egg\suds\version.pyc'>


WSDL如下

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:tns="http://wsdl.CLT.org/Docs/"
                  xmlns:fENTERPRISE="http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISE"
                  name="SendRange"
                  targetNamespace="http://wsdl.CLT.org/Docs/">
    <wsdl:types>
      <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
                  xmlns:commonENTERPRISE="http://xmlns.CLT.corp/Core/ENTERPRISE/Common/ENTERPRISE"
                  xmlns:fENTERPRISEOUT="http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISEOUT"
                  xmlns:tns="http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISE"
                  targetNamespace="http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISE"
                  elementFormDefault="qualified">
         <element name="SendNumberRangesRequestENTERPRISE" type="tns:SendNumberRangesRequestENTERPRISEType"/>
         <element name="SendNumberRangesResponseENTERPRISE" type="tns:SendNumberRangesResponseENTERPRISEType"/>
         <complexType name="SendNumberRangesRequestENTERPRISEType">
            <complexContent>
               <extension base="commonENTERPRISE:ENTERPRISEType">
                  <sequence>
                    <element name="DataZone" type="tns:SendNumberRangesRequestElementType"/>
                  </sequence>
               </extension>
            </complexContent>
         </complexType>
         <complexType name="SendNumberRangesResponseENTERPRISEType">
            <complexContent>
               <extension base="commonENTERPRISE:ResponseENTERPRISEType"></extension>
            </complexContent>
         </complexType>
         <complexType name="SendNumberRangesRequestElementType">
            <sequence>
               <element ref="fENTERPRISEOUT:asignacionNumberRanges"/>
            </sequence>
         </complexType>
      </xsd:schema>
      <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
                  xmlns:commonENTERPRISE="http://xmlns.CLT.corp/Core/ENTERPRISE/Common/ENTERPRISE"
                  targetNamespace="http://xmlns.CLT.corp/Core/ENTERPRISE/Common/ENTERPRISE"
                  elementFormDefault="qualified">
         <xsd:element name="ENTERPRISEHeader" type="commonENTERPRISE:ENTERPRISEHeaderType"/>
         <xsd:element name="ErrorDetail" type="commonENTERPRISE:ErrorDetailType" nillable="true"/>
         <xsd:complexType name="ENTERPRISEHeaderType">
            <xsd:sequence>
               <xsd:element name="ENTERPRISEID" type="xsd:string"/>
               <xsd:element name="CreationDateTime" type="xsd:dateTime" minOccurs="0"/>
               <xsd:element name="Sender" type="commonENTERPRISE:SenderType"/>
               <xsd:element name="Target" type="xsd:string" minOccurs="0"/>
               <xsd:element name="ENTERPRISETracking" type="commonENTERPRISE:ENTERPRISETrackingType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="Addressing" type="commonENTERPRISE:ENTERPRISEAddressingType" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="SenderType">
            <xsd:sequence>
               <xsd:element name="Application" type="xsd:string"></xsd:element>
               <xsd:element name="Country" type="xsd:string"></xsd:element>
               <xsd:element name="BusinessUnit" type="xsd:string"></xsd:element>
               <xsd:element name="LegalEntity" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="1"></xsd:element>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="ENTERPRISEType">
            <xsd:sequence>
               <xsd:element ref="commonENTERPRISE:ENTERPRISEHeader"/>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="ResponseENTERPRISEType">
            <xsd:sequence>
               <xsd:element ref="commonENTERPRISE:ENTERPRISEHeader"/>
               <xsd:element name="ReturnCode" type="xsd:string"/>
               <xsd:element name="ReturnMessage" type="xsd:string"/>
               <xsd:element name="ErrorCode" type="xsd:string" nillable="true" minOccurs="0"/>
               <xsd:element ref="commonENTERPRISE:ErrorDetail" minOccurs="0"/>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="ErrorDetailType">
            <xsd:sequence>
               <xsd:element name="ErrorType" type="xsd:string" minOccurs="0"/>
               <xsd:element name="HandlerServiceName" type="xsd:string" minOccurs="0"/>
               <xsd:element name="SourceApplication" type="xsd:string" minOccurs="0"/>
               <xsd:element name="SourceServiceName" type="xsd:string" minOccurs="0"/>
               <xsd:element name="SourceErrorCode" type="xsd:string" minOccurs="0"/>
               <xsd:element name="SourceErrorMessage" type="xsd:string" minOccurs="0"/>
               <xsd:element name="SourceErrorTrace" type="xsd:string" minOccurs="0"/>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="ENTERPRISETrackingType">
            <xsd:sequence>
               <xsd:element name="FileName" minOccurs="0">
                  <xsd:simpleType>
                    <xsd:restriction base="xsd:string"/>
                  </xsd:simpleType>
               </xsd:element>
               <xsd:element name="ParentENTERPRISEID" type="xsd:string" nillable="true" minOccurs="0"></xsd:element>
               <xsd:element name="IntegrationCode" type="xsd:string" nillable="true" minOccurs="0"></xsd:element>
               <xsd:element name="ReferenceID" type="xsd:string" nillable="true" minOccurs="0"></xsd:element>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="ENTERPRISEAddressingType">
            <xsd:sequence>
               <xsd:element name="ReplyToAddress" type="xsd:string" nillable="true" minOccurs="0"></xsd:element>
               <xsd:element name="CorrelID" type="xsd:string" nillable="true" minOccurs="0"></xsd:element>
            </xsd:sequence>
         </xsd:complexType>
      </xsd:schema>
      <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
                  xmlns:tns="http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISEOUT"
                  targetNamespace="http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISEOUT"
                  attributeFormDefault="unqualified"
                  elementFormDefault="qualified">
         <element name="asignacionNumberRanges">
            <complexType>
               <sequence>
                  <element type="long" name="BusCode"/>
                  <element type="string" name="CodeDocType"/>
                  <element type="string" name="CodeLocal"/>
                  <element type="string" name="appOrigin"/>
                  <element type="long" name="InitialNumber"/>
                  <element type="long" name="FinalNumber"/>
               </sequence>
            </complexType>
         </element>
      </xsd:schema>
    </wsdl:types>

    <wsdl:message name="SendNumberRangesRequestMessage">
        <wsdl:part element="fENTERPRISE:SendNumberRangesRequestENTERPRISE" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="SendNumberRangesResponseMessage">
        <wsdl:part element="fENTERPRISE:SendNumberRangesResponseENTERPRISE" name="parameters"/>
    </wsdl:message>

    <wsdl:portType name="SendRangePort">
        <wsdl:operation name="SendRange">
            <wsdl:input message="tns:SendNumberRangesRequestMessage"/>
            <wsdl:output message="tns:SendNumberRangesResponseMessage"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="SendRangeSOAP" type="tns:SendRangePort">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="SendRange">
            <soap:operation soapAction="http://wsdl.CLT.org/Docs/NumberRanges/SendRange"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="SendRange">
        <wsdl:port name="SendRangePort" binding="tns:SendRangeSOAP">
          <soap:address location="http://127.0.0.1/SendRange" />
        </wsdl:port>
  </wsdl:service>

</wsdl:definitions>


当我收到Type Not Found异常时,我正在按以下方式使用suds

>>> from suds.client import Client
>>> wsdl_url='http://127.0.0.1:8000/LoadRangeWSDL'
>>> client_object = Client(wsdl_url)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\suds\client.py", line 115, in __init__
  File "build\bdist.win32\egg\suds\reader.py", line 150, in open
  File "build\bdist.win32\egg\suds\wsdl.py", line 159, in __init__
  File "build\bdist.win32\egg\suds\wsdl.py", line 220, in build_schema
  File "build\bdist.win32\egg\suds\xsd\schema.py", line 94, in load
  File "build\bdist.win32\egg\suds\xsd\schema.py", line 319, in dereference
  File "build\bdist.win32\egg\suds\xsd\sxbasic.py", line 508, in dependencies
suds.TypeNotFound: Type not found: '(ENTERPRISEType, http://xmlns.CLT.corp/Core/ENTERPRISE/Common/ENTERPRISE, )'


我仔细检查了一下,并确定在WSDL中定义了ENTERPRISEType。请指导。

最佳答案

看来医生可以解决您的问题。

from suds.xsd.doctor import Import, ImportDoctor
imp1 = Import('http://xmlns.CLT.corp/Core/ENTERPRISE/Common/ENTERPRISE')
imp2 = Import('http://xmlns.CLT.corp/Docs/NumberRanges/ENTERPRISEOUT')
doctor = ImportDoctor(imp1, imp2)
client = Client('http://127.0.0.1:8000/LoadRangeWSDL', doctor=doctor)

10-08 10:57