Search code examples
pythonxmlsoapwsdlsuds

Can't create an instance of an array type not listed by suds


i am making a client to access a wsdl and print the response..later on print the response on a web page..however right now I am stuck in the initial code itself....i believe that suds is generating the wrong client methods signature for the wsdl give...the following is my code and the error i get:

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'

i am not sure y its finding nso:rows in the first place. Because the type is a responseRow object in the WSDL def but its expecting a row object...so I can't send in the msg request! I need to send in the details in the requestRow object. Help! I am new at this...

EDIT: i tried sending in a Request object instead of the rows...that didn't work and i got the following error

>>> 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> '

I am attaching the xml for this as well

<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>

Solution

  • its solved! ideally rows here was just a python list..all i needed to do was add a row object in it of type requestRow which solved my problem... !