Python: Sending Raw XML via Suds (jurko)

3.3k views Asked by At

I'm interfacing with a SOAP API, wherein a particular method requires a raw XML string as a parameter. Like so:

import suds.client as sudscl

client = sudscl.Client('http://host/ws.wsdl', location='http://host/ws')

session = 'test123'
options = '<rawXML><Item>Foobar</Item></rawXML>'

result = client.service.ExecuteSearch(session, options)

Pretty straight-forward. However, suds HTML-encodes the XML string I just sent in, like this:

 <?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:ns0="http://host/ws">
   <SOAP-ENV:Header/>
   <ns1:Body>
     <ns0:ExecuteSearch>
        <ns0:session>test123</ns0:session>
        <ns0:options>
          &lt;rawXML&rt;&lt;Item&rt;Foobar&lt;/Item&rt;&lt;/rawXML&rt;
        </ns0:options>
     </ns0:ExecuteSearch>
   </ns1:Body>
 </SOAP-ENV:Envelope>

Boo! Is there any way to get suds to pass in the XML string un-altered?

Thanks!

1

There are 1 answers

0
Joshua Pruitt On BEST ANSWER

Ok, got it.

from suds.sax.text import Raw
import suds.client as sudscl

client = sudscl.Client('http://host/ws.wsdl', location='http://host/ws')

session = 'test123'
options = Raw('<rawXML><Item>Foobar</Item></rawXML>')

result = client.service.ExecuteSearch(session, options)