Thursday, 15 May 2014

python 2.7 - Get SOAP attachment -



python 2.7 - Get SOAP attachment -

there lot of questions same subject, no replies, receiving. there exist illustration how send attachment, didn't found how receive it. there solution on python receiving attachments? agree alter soap tool suds works.

thank in advance.

i solved suds.

def getwithfile(self, client, servicename, modelthings): func = client.get_suds_func('retrieve' + servicename) clientclass = func.clientclass({}) soapclient = clientclass(func.client, func.method) binding = func.method.binding.input soap_xml = binding.get_message(func.method, [modelthings], {}) soap_xml.children[0].children[1].children[0].attributes.append(u'attachmentinfo="true"') soap_xml.children[0].children[1].children[0].attributes.append(u'attachmentdata="true"') soap_xml.children[0].children[1].children[0].attributes.append(u'ignoreemptyelements="true"') soapclient.last_sent(soap_xml) plugins = plugincontainer(soapclient.options.plugins) plugins.message.marshalled(envelope=soap_xml.root()) if soapclient.options.prettyxml: soap_xml = soap_xml.str() else: soap_xml = soap_xml.plain() soap_xml = soap_xml.encode('utf-8') plugins.message.sending(envelope=soap_xml) request = request(soapclient.location(), soap_xml) request.headers = soapclient.headers() reply = soapclient.options.transport.send(request) print(reply) files = [] boundary = self.find_substring(reply.headers['content-type'], 'boundary="', '"') if boundary not "": list_of_data = reply.message.split(boundary) list_of_data.pop(0) list_of_data.pop(len(list_of_data) - 1) soap_body = '<soap-env:envelope' + self.find_substring(list_of_data[0], '<soap-env:envelope', '</soap-env:envelope>') + '</soap-env:envelope>' line in list_of_data[1:]: file = smfile() files.append(file) file.filename = self.find_substring(line, 'content-location: ', '\r\n') file.key = self.find_substring(line, 'content-id: ', '\r\n') idx = line.index( 'content-id:' ) start_idx = line.index( '\r\n\r\n' , idx ) + len('\r\n\r\n') fin_idx = line.rindex( '\r\n--', start_idx ) file.body = line[start_idx: fin_idx] file.size = fin_idx - start_idx else: soap_body = '<soap-env:envelope' + self.find_substring(reply.message, '<soap-env:envelope', '</soap-env:envelope>') + '</soap-env:envelope>' ctx = plugins.message.received(reply=soap_body) soap_body = ctx.reply if soapclient.options.retxml: reply = soap_body else: reply = soapclient.succeeded(binding, soap_body) dict = {} self.fieldstodict(answer.model.instance, dict) homecoming {u'body': answer, u'files': files}

here extract low level of suds, beingness able prepare field in envelope. then, after reply got, parse boundaries , receive many files, got.

python-2.7 suds

No comments:

Post a Comment