I am trying to use suds to make a request to a remote service. Thus:
from suds.client import Client from suds.sax.element import Element from suds.sax.attribute import Attribute from suds.plugin import MessagePlugin url='https://myemployer.com?wsdl' c = Client(url) t = c.service.Authenticate('Gameon', 'blah') t = t.Authenticate.Status.Token
header_root = Element('AuthHeader') header_token = Element('Token').setText(t) header_attribute = Attribute('xmlns', "http://myemployer.com/") soap_header = header_root.insert(header_token) soap_header.append(header_attribute)
class NamespaceFixer(MessagePlugin): ''' must add namespace prefix to all parameters ''' def marshalled(self, context): body = context.envelope[1] for i in body[0]: i.setPrefix('ns0') print "******* element after setting prefix: %s ********" % i.plain() print context
nsf = NamespaceFixer() c.set_options(soapheaders=soap_header, plugins=[nsf])
from suds.sax.element import Element
ba2 = Element('badgeAwards') ba = Element('AwardBadge') ba2.append(ba) entid = Element('EnterpriseID').setText('jhoov11') ba.append(entid) btype = Element('badgeTypeID').setText('30') ba.append(btype) startdate = Element('startDate').setText('2013-8-22') ba.append(startdate) enddate = Element('endDate').setText('9999-12-31') ba.append(enddate) isdeleted = Element('isDeleted').setText('0') ba.append(isdeleted)
includeSuccess = Element('includeSuccessStatus').setText('false')
c.service.AwardBadgesBatch(badgeAwards= ba2, includeSuccessStatus=includeSuccess)
c.last_sent().plain()
u'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns0=" http://myemployer.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/%22%3ESOAP-ENV:Header<AuthHeader xmlns="http://myemployer.com/ "><Token>blah</Token></AuthHeader></SOAP-ENV:Header>ns1:Bodyns0:AwardBadgesBatchns0:badgeAwards/ns0:includeSuccessStatus/</ns0:AwardBadgesBatch></ns1:Body></SOAP-ENV:Envelope>'
So it seems that badgeAwards and includeSuccessStatus are being passed as empty? Is this intended behavior? Have I missed something here? How am I supposed to set those parameters to actual values?