获取SOAP附件

问题描述 投票:-1回答:1

有很多具有相同主题的问题,但没有回复,特别是有关接收。存在例如如何send attachment,但我没有找到如何接受它。是否有附件收发蟒蛇上任何解决方案?我甚至同意改变从沫我SOAP工具,任何会的作品。

先感谢您。

python-2.7 suds
1个回答
0
投票

我用肥皂水解决它。

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 is 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>'

        for 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:
        answer = soap_body
    else:
        answer = SoapClient.succeeded(binding, soap_body)

    dict = {}
    self.FieldsToDict(answer.model.instance, dict)

    return {u'body': answer, u'Files': Files}

在这里,我们提取出皂液的一些低级别,能够修复任何信封领域。然后,答复了以后,我们解析所有界限,获得尽可能多的文件,因为我们得到了。

© www.soinside.com 2019 - 2024. All rights reserved.