AWS_Developer
AWS_Developer

Reputation: 856

How to send multiple values under single tag of SOAP Request in zeep python

I need to send request like this:

<soap:Body>
      <ver:Notification>
         <!--Optional:-->
         <ver:messages>
            <!--Zero or more repetitions:-->
            <ver:Check>
               <ver:ID>324007</ver:ID>
               <ver:BranchList>
                  <ver:Branch >
                     <ver:Area>
                        <ver:XAxis>21.23</ver:XAxis>
                        <ver:YAxis>-09.11</ver:YAxis>
                     </ver:Area>
                  </ver:Branch>
               </ver:BranchList>
            </ver:Check>
            <ver:Check>
               <ver:ID>002345</ver:ID>
               <ver:BranchList>
                  <ver:Branch >
                     <ver:Area>
                        <ver:XAxis>23.334</ver:XAxis>
                        <ver:YAxis>-11.23</ver:YAxis>
                     </ver:Area>
                  </ver:Branch>
               </ver:BranchList>
            </ver:Check>
         </ver:messages>
      </ver:Notification>
   </soap:Body>

I am preparing the request using Zeep library in python. I am getting some values from upstream in 'upstream_messages' and iterating it and creating the list_of_messages like below:

list_of_messages = []
        for i in upstream_messages:
            list_of_messages .append(
                {'Check': {'ID': i[0],
                           'BranchList':
                               {'Branch':
                                   {
                                       'Area': {'XAxis': i[4], 'YAxis': i[5]}
                                   }
                               }
                           }
                }

            )

But when I am checking the request using below code:

request = client.create_message(client.service, 'Notification', messages=list_of_messages )
logger.info(etree.tostring(request, pretty_print=True))

Then getting only first 'check' tag with ID=324007 like below:

<soap-env:Envelope xmlns:soap-env="some http url/soap/envelope/">\n  
  <soap-env:Body>\n    
     <ns0:Notification xmlns:ns0="some http url /Version_1.1_Release">\n      
       <ns0:messages>\n        
         <ns0:Check>\n          
           <ns0:ID>324007</ns0:ID>\n          
           <ns0:BranchList>\n            
             <ns0:Branch>\n              
               <ns0:Area>\n                
                 <ns0:XAxis>21.23</ns0:XAxis>\n                
                 <ns0:YAxis>-09.11</ns0:YAxis>\n              
               </ns0:Area>\n              
             </ns0:Branch>\n          
           </ns0:BranchList>\n        
          </ns0:Check>\n      
        </ns0:messages>\n    
      </ns0:Notification>\n  
    </soap-env:Body>\n
  </soap-env:Envelope>

Please suggest what am I doing wrong. I tried using messages=[list_of_messages] making list of list for list_of_messages but then i get output without the messages tag

Upvotes: 3

Views: 691

Answers (1)

webh
webh

Reputation: 379

You need to use Checks as an array and not list_of_messages. See https://github.com/mvantellingen/python-zeep/issues/272.

Following code should work:

list_of_messages = {'Check': []}
        for i in upstream_messages:
            list_of_messages['Check'].append(
                {'ID': i[0],
                   'BranchList':
                       {'Branch':
                           {
                               'Area': {'XAxis': i[4], 'YAxis': i[5]}
                           }
                       }
                   }

            )

Upvotes: 2

Related Questions