Reputation: 157
I'm trying to call a soap method with zeep (v 3.4.0) and pass a list of objects to that method. Inspecting the xml presentation of the request shows an empty list.
from lxml import etree
from requests import Session
from requests.auth import HTTPDigestAuth # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep.transports import Transport
session = Session()
session.auth = HTTPDigestAuth('user', 'pass')
client = Client('http:service.local/services.wsdl',
transport=Transport(session=session))
factory = client.type_factory('ns0')
o1 = factory.objectTypePrint('name1', 'val1')
o2 = factory.objectTypePrint('name2', 'val2')
o3 = factory.objectTypePrint('name3', 'val3')
node = client.create_message(client.service, 'printFormat', numbers=1, jobID='test', objects=[o1,o2,o3])
print(etree.tostring(node, pretty_print=True))
The result looks like
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:printFormatRequest xmlns:ns0="http://www.cab.de/WSSchema">
<ns0:objects/>
<ns0:jobID>test</ns0:jobID>
<ns0:numbers>1</ns0:numbers>
</ns0:printFormatRequest>
</soap-env:Body>
</soap-env:Envelope>
This is from the wsdl:
<xsd:complexType name="printFormat">
<xsd:sequence>
<xsd:element name="objects">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="fObject" minOccurs="0" maxOccurs="unbounded" type="tns:objectTypePrint"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="jobID" type="xsd:string"/>
<xsd:element name="numbers" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
I'm expecting a list of objects in the <ns0:objects>
tag but it's empty.
Upvotes: 0
Views: 2823
Reputation: 157
I solved it by myself.
For other struggling with this problem:
zeep can show the loaded wsdl info with client.wsdl.dump()
The result contains this:
ns0:printFormat(objects: {fObject: ns0:objectTypePrint[]}, jobID: xsd:string, numbers: xsd:int)
So the working code for this method looks like:
from lxml import etree
from requests import Session
from requests.auth import HTTPDigestAuth # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep.transports import Transport
session = Session()
session.auth = HTTPDigestAuth('user', 'pass')
client = Client('http:service.local/services.wsdl',
transport=Transport(session=session))
factory = client.type_factory('ns0')
o1 = factory.objectTypePrint('name1', 'val1')
o2 = factory.objectTypePrint('name2', 'val2')
o3 = factory.objectTypePrint('name3', 'val3')
o = { 'fObject': [ o1, o2, o3 ] }
node = client.create_message(client.service, 'printFormat', numbers=1, jobID='test', objects=o)
print(etree.tostring(node, pretty_print=True))
Upvotes: 3