Pavel Chelnokov
Pavel Chelnokov

Reputation: 1

Python zeep how to send multiple values ​in one request

I apologize right away for my poor English.

I have a problem with sending multiple values ​​via zeep client. There is a conditional method

<s:element name="GetSomething">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="id" type="s:string"/>
        </s:sequence>
    </s:complexType>
</s:element>

If I need to get 1 value, then there is no problem. I am using this code:

WSDL = 'example.asmx?WSDL'

session = Session()
transport = Transport(session=session)
client = Client(wsdl=WSDL, transport=transport)
res = client.service.GetCompanyExtendedReport(id='1')
print(res)

but if i need to get multiple values. I will give an example xml

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:GetSomething xmlns:ns1='http://examplesoapapi.ru/idk'>
      <ns1:id>1</ns1:id>
      <ns1:id>2</ns1:id>
      <ns1:id>3</ns1:id>
      <ns1:id>4</ns1:id>
      <ns1:id>5</ns1:id>
    </ns1:GetStateContractReport>
  </s11:Body>
</s11:Envelope>

then I don't understand how can I send this kind of request via zeep

WSDL = 'example.asmx?WSDL'

session = Session()
transport = Transport(session=session)
client = Client(wsdl=WSDL, transport=transport)
res = client.service.GetCompanyExtendedReport(id='1', id='2', id='3', ???)
print(res)

it's clear that I can send such requests in a loop, but this is not what I need...

Upvotes: 0

Views: 462

Answers (2)

Adesh Dangi
Adesh Dangi

Reputation: 1

When key or node is sequences, in XML it can be:

<tag1> //sequence
   <tag_a> 1 </tag_a>
   <tag_a> 2 </tag_a>
</tag1>

With zeep it must work like:

{"tag1":[{"tag_a":1},{"tag_a":2}] }

In your case:

res = client.service.GetCompanyExtendedReport([{"id":'1'}, {"id":'2'}, {"id":'3'}])
print(res)

Upvotes: 0

Bogdan
Bogdan

Reputation: 24580

You can't.

Your id element is defined as:

<s:element minOccurs="0" maxOccurs="1" name="id" type="s:string"/>

That means zero or one id. Not more.

You either need to make a loop for more calls, or you look for another operation within your service that accepts a list of ids, not just zero or one (if that even exists).

Even if you make a call like in your example, the service will either use one at most or it will reject the request entirely, simply because SOAP is a protocol and a SOAP service has a specific contract defined. It accepts requests that conform to that contract, not requests that you wish you would have (read this for an extended explanation).

Upvotes: 0

Related Questions