python - Why am I not getting the correct response? -
i complete python noob
foreshadowing done, trying parse information out of soap response. body of reponse below:
<soap:body> <processmessageresponse xmlns="http://www.starstandards.org/webservices/2005/10/transport"> <payload> <content id="content0"> <customerlookupresponse xmlns=""> <customer> <companynumber>zq1</companynumber> <customernumber>1051012</customernumber> <typecode>i</typecode> <lastname>name</lastname> <firstname>basic</firstname> <middlename/> <salutation/> <gender/> <language/> <address1/> <address2/> <address3/> <city/> <county/> <statecode/> <zipcode>0</zipcode> <phonenumber>0</phonenumber> <businessphone>0</businessphone> <businessext>0</businessext> <faxnumber>0</faxnumber> <birthdate>0</birthdate> <driverslicense/> <contact/> <preferredcontact/> <mailcode/> <taxexmptnumber/> <assignedsalesperson/> <customertype/> <preferredphone/> <cellphone>0</cellphone> <pagephone>0</pagephone> <otherphone>0</otherphone> <otherphonedesc/> <email1/> <email2/> <optionalfield/> <allowcontactbypostal/> <allowcontactbyphone/> <allowcontactbyemail/> <businessphoneextension/> <internationalbusinessphone/> <internationalcellphone/> <externalcrossreferencekey>0</externalcrossreferencekey> <internationalfaxnumber/> <internationalotherphone/> <internationalhomephone/> <customerpreferredname/> <internationalpagerphone/> <preferredlanguage/> <lastchangedate>20130401</lastchangedate> <vehicles/> <ccid/> <cccd>0</cccd> </customer> </customerlookupresponse> </content> </payload> </processmessageresponse> </soap:body>
and have following code snippet show have done parse out response want:
customer_number = '' customer_first_name = '' customer_last_name = '' def send_customer_lookup(data): soap_action = 'http://www.starstandards.org/webservices/2005/10/transport/operations/processmessage' source_port = random.randint(6000, 20000) webservice = httplib.httpsconnection('otqa.arkona.com', source_address=('', source_port)) webservice.putrequest('post', '/opentrack/webservice.asmx?wsdl') webservice.putheader('user-agent', 'opentrack-heartbeat') webservice.putheader('content-type', 'application/soap+xml') webservice.putheader('content-length', '%d' % len(data)) webservice.putheader('soapaction', soap_action) webservice.endheaders() webservice.send(data) response = webservice.getresponse() response_xml = str(response.read()) doc = et.fromstring(response_xml) customer in doc.findall('.//{http://www.starstandards.org/webservices/2005/10/transport}payload'): global customer_number global customer_first_name global customer_last_name customer_number = customer.findtext('{http://www.starstandards.org/webservices/2005/10/transport}customernumber') customer_first_name = customer.findtext('{http://www.starstandards.org/webservices/2005/10/transport}firstname') customer_last_name = customer.findtext('{http://www.starstandards.org/webservices/2005/10/transport}lastname') webservice.close() return customer_number, customer_first_name, customer_last_name, response_xml
i not why getting output of ' ', ' ', ' ', <xml response>...
it looks overspecifying field names, therefore don't match anything, therefore for customer in ...
never runs. try this:
import httplib import xml.etree.elementtree et def send_customer_lookup(data): soap_action = 'http://www.starstandards.org/webservices/2005/10/transport/operations/processmessage' source_port = random.randint(6000, 20000) httplib.httpsconnection('otqa.arkona.com', source_address=('', source_port)) webservice: webservice.putrequest('post', '/opentrack/webservice.asmx?wsdl') webservice.putheader('user-agent', 'opentrack-heartbeat') webservice.putheader('content-type', 'application/soap+xml') webservice.putheader('content-length', '%d' % len(data)) webservice.putheader('soapaction', soap_action) webservice.endheaders() webservice.send(data) response_xml = str(webservice.getresponse().read()) doc = et.fromstring(response_xml) results = [] customer in doc.findall('.//customerlookupresponse/'): customer_number = customer.findtext('customernumber') customer_first_name = customer.findtext('firstname') customer_last_name = customer.findtext('lastname') results.append((customer_number, customer_first_name, customer_last_name)) return results
also, global variable names evil; presume added them because getting 'variable not defined' errors? should have been clue for-loop not getting run.
Comments
Post a Comment