Feb-05-2019, 09:01 PM
(This post was last modified: Feb-05-2019, 09:05 PM by littleGreenDude.)
Definitely not as pretty, or as elegant as I was hoping. I was able to get things working by constructing the whole soap envelope (incl header) and posting that.
For completeness, here are the 2 urls that helped me reach my solution:
Python XML HTTP Post to send a SOAP message
urllib2 — extensible library for opening URLs
def api_login3(self, username, password): SM_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetAccountInfo xmlns="http://tempuri.org/"> <signinID>%s</signinID> <password>%s</password> </GetAccountInfo> </soap:Body> </soap:Envelope> """ SoapMessage = SM_TEMPLATE % (username, password) print(SoapMessage) request = urllib2.Request(self.ApiLoginCheck, SoapMessage) request.add_header("Host", self.ApiHost) request.add_header("User-Agent", "Python post") request.add_header("Content-type", "text/xml; charset=\"UTF-8\"") request.add_header("Content-length", "%d" % len(SoapMessage)) request.add_header("SOAPAction", "http://tempuri.org/GetAccountInfo") print(request) response = urllib2.urlopen(request) self.last_response_code = response.code self.last_response_content = response.read().decode('utf-8') if response.code == 200: print(response) print(self.last_response_content) root = ET.fromstring(self.last_response_content) xmlns = {'t': 'http://tempuri.org/'} emails = root.findall('.//t:accountEmail', namespaces=xmlns) for email in emails: print(email) if email.text == '' or email.text == None: return 0 else: return 1 else: return 0
For completeness, here are the 2 urls that helped me reach my solution:
Python XML HTTP Post to send a SOAP message
urllib2 — extensible library for opening URLs