【问题标题】:Can't create an instance of an array type not listed by suds无法创建 suds 未列出的数组类型的实例
【发布时间】:2011-11-09 12:50:08
【问题描述】:

我正在让客户端访问 wsdl 并打印响应..稍后在网页上打印响应..但是现在我被困在初始代码本身..我相信 suds 正在生成wsdl 的错误客户端方法签名给出...以下是我的代码和我得到的错误:

print client

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( IWS_GeocodeService_GB ) tns="http://www.g1.com/"
   Prefixes (1)
      ns0 = "http://www.g1.com/services/IWS_GeocodeService_GB"
   Ports (1):
      (IWS_GeocodeService_GBPort)
         Methods (1):
            IWS_GeocodeService_GB(ns0:context context, ns0:options options, ns0:rows rows, )
         Types (7):
            ns0:IWS_GeocodeService_GBRequest
            ns0:IWS_GeocodeService_GBResponse
            ns0:context
            ns0:options
            ns0:requestRow
            ns0:responseRow
            ns0:user_field


>>> print context1
(context){
   account.id = "spectrumd3v"
   account.password = "spectrumd3v"
 }
>>> rows = client.factory.create('ns0:rows')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 234, in create
    raise TypeNotFound(name)
suds.TypeNotFound: Type not found: 'ns0:rows'

我不确定你是否首先找到了 nso:rows。因为该类型是 WSDL def 中的 responseRow 对象,但它需要一个行对象……所以我无法发送 msg 请求!我需要在 requestRow 对象中发送详细信息。帮助!我是新手……

编辑:我尝试发送请求对象而不是行...这不起作用,我收到以下错误

>>> resp = client.service.IWS_GeocodeService_GB(context,options,Request)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 649, in send
result = self.failed(binding, e)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 702, in failed
r, p = binding.get_fault(reply)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Unmarshalling Error: unexpected element   (uri:"http://www.g1.com/services/IWS_GeocodeService_GB", local:"context"). Expected elements are <{http://www.g1.com/services/IWS_GeocodeService_GB}row> '

我也附上了这个xml

<wsdl:definitions name="IWS_GeocodeService_GB" targetNamespace="http://www.g1.com/">
  <wsdl:types>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://www.g1.com/services/IWS_GeocodeService_GB">
      <xs:element name="requestRow" type="tns:requestRow"/>
      <xs:element name="responseRow" type="tns:responseRow"/>
      <xs:complexType name="IWS_GeocodeService_GBRequest">
         <xs:sequence>
          <xs:element form="qualified" name="context" type="tns:context"/>
          <xs:element form="qualified" minOccurs="0" name="options" type="tns:options"/>           
          <xs:element form="qualified" name="rows">
             <xs:complexType>
              <xs:sequence>
                <xs:element form="qualified" maxOccurs="unbounded" name="row" type="tns:requestRow"/>
              </xs:sequence>
             </xs:complexType>
          </xs:element>
         </xs:sequence>
      </xs:complexType>
      <xs:complexType name="context">
         <xs:sequence>
            <xs:element form="qualified" name="account.id" type="xs:string"/>                      
            <xs:element form="qualified" minOccurs="0" name="account.password" type="xs:string"/>
         </xs:sequence>
      </xs:complexType>
      <xs:complexType name="options">
         <xs:sequence/>
      </xs:complexType>
      <xs:complexType name="requestRow">
         <xs:all>
            <xs:element form="qualified" minOccurs="0" name="AddressLine1" type="xs:string"/>
            <xs:element form="qualified" minOccurs="0" name="AddressLine2" type="xs:string"/>
            <xs:element form="qualified" minOccurs="0" name="City" type="xs:string"/>                
            <xs:element form="qualified" minOccurs="0" name="PostalCode" type="xs:string"/>
            <xs:element form="qualified" minOccurs="0" name="Country" type="xs:string"/>             
            <xs:element form="qualified" minOccurs="0" name="user_fields"><xs:complexType>

【问题讨论】:

  • ns0:rows 未在 wsdl 中指定的类型中列出;你期望它做什么?你为什么这么期待?您可能需要创建一个ns0:requestRows 的python 列表吗?
  • 我意识到在查看 xml 之后...我尝试将其作为 ns0:requestRow 列表发送,但它给出了 requestRow type not found 错误
  • suds.TypeNotFound: 找不到类型:'requestRow' >>> 打印行 {'requestRow': (requestRow){ AddressLine1 = "47 Stirling road" AddressLine2 = "Wood Green" City = None PostalCode = "N22 5BL" 国家 = 无 user_fields = (user_fields){ user_field[] = } }}
  • 我发现一些日志错误:DEBUG:suds.client:http failed: schemas.xmlsoap.org/soap/envelope/… Error: unexpected element (uri:"g1.com/services/IWS_GeocodeService_GB", local: "AddressLine1")。预期的元素是 <{g1.com/services/IWS_GeocodeService_GB}row>
  • 更新:每次在行对象(responseRow 类型的对象)中填写 AddressLine1 字段或任何其他字段时,我都会收到上述错误。如果我将行作为空传递。 .即所有字段都设置为none然后服务运行没有错误但我没有得到响应对象中返回的任何内容。

标签: python xml soap wsdl suds


【解决方案1】:

解决了!理想情况下,这里的行只是一个 python 列表..我需要做的就是在其中添加一个 requestRow 类型的行对象,这解决了我的问题......!

【讨论】:

    猜你喜欢
    • 2018-05-25
    • 2020-02-02
    • 2021-11-15
    • 2021-10-01
    • 1970-01-01
    • 2016-10-04
    • 2021-10-24
    • 2020-05-10
    • 1970-01-01
    相关资源
    最近更新 更多