python - Using urllib2 to do a SOAP POST, but I keep getting an error -
i trying api call via soap post , keep getting "typeerror: not valid non-string sequence or mapping object." @ data = urllib.urlencode(values)
sm_template = """<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:header> <autotaskintegrations xmlns="http://autotask.net/atws/v1_5/"> <partnerid>partner id</partnerid> </autotaskintegrations> </soap:header> <soap:body> <getthresholdandusageinfo xmlns="http://autotask.net/atws/v1_5/"> </getthresholdandusageinfo> </soap:body> </soap:envelope>""" values = sm_template%() data = urllib.urlencode(values) req = urllib2.request(site, data) response = urllib2.urlopen(req) the_page = response.read()
any appreciated.
the urllib.urlencode
function expects sequence of key-value pairs or mapping type dict
:
>>> urllib.urlencode([('a','1'), ('b','2'), ('b', '3')]) 'a=1&b=2&b=3'
to perform soap http post, should leave sm_template blob as-is , set post body, add content-type header post body's encoding , charset. example:
data = sm_template headers = { 'content-type': 'application/soap+xml; charset=utf-8' } req = urllib2.request(site, data, headers)
Comments
Post a Comment