dandu
dandu

Reputation: 800

python soappy add header

I have the following PHP example code:

$client = new SoapClient("http://example.com/example.wsdl");

$h = Array();
array_push($h, new SoapHeader("http://example2.com/example2/", "h", "v"));
$client->__setSoapHeaders($h);

$s = $client->__soapCall('Op', $data);

My question: what's the SOAPpy equivalent for the SoapHeader() and __setSoapHeaders() part?

Related question

Upvotes: 1

Views: 1124

Answers (1)

jfs
jfs

Reputation: 414069

Here's an example using suds library (an alternative to SOAPpy). It assumes that the custom header is not defined in the wsdl.

from suds.client      import Client
from suds.sax.element import Element

client = Client("http://example.com/example.wsdl")

# <tns:h xmlns:tns="http://example2.com/example2/">v</tns:h>
tns = ("tns", "http://example2.com/example2/")
h = Element('h', ns=tns).setText('v')
client.set_options(soapheaders=h) 
#
s = client.service.Op(data)

Upvotes: 1

Related Questions