Python 2.7 获取SOAP附件

Python 2.7 获取SOAP附件,python-2.7,suds,Python 2.7,Suds,有很多关于同一主题的问题,但没有回答,特别是关于接收的问题。有这样的例子,但我没有找到如何接收它。 python上有没有接收附件的解决方案?我甚至同意将我的SOAP工具从suds更改为任何可以工作的工具 提前谢谢你。我用肥皂水解决了这个问题 def GetWithFile(self, client, servicename, modelthings): func = client.get_suds_func('Retrieve' + servicename) clientclas

有很多关于同一主题的问题,但没有回答,特别是关于接收的问题。有这样的例子,但我没有找到如何接收它。 python上有没有接收附件的解决方案?我甚至同意将我的SOAP工具从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 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}
def GetWithFile(self、client、servicename、modelsthings):
func=client.get\u suds\u func('Retrieve'+servicename)
clientclass=func.clientclass({})
SoapClient=clientclass(func.client,func.method)
binding=func.method.binding.input
soap_xml=binding.get_消息(func.method,[modelsthings],{})
soap_xml.children[0]。children[1]。children[0]。属性。追加(u'attachmentInfo=“true”)
soap_xml.children[0]。children[1]。children[0]。attributes.append(u'attachmentData=“true”)
soap_xml.children[0]。children[1]。children[0]。属性。追加(u'ignoreEmptyElements=“true”)
SoapClient.last_发送(soap_xml)
plugins=PluginContainer(SoapClient.options.plugins)
plugins.message.marshalled(envelope=soap\u xml.root())
如果是SoapClient.options.prettyxml:
soap\u xml=soap\u xml.str()
其他:
soap\u xml=soap\u xml.plain()
soap\u xml=soap\u xml.encode('utf-8')
plugins.message.sending(信封=soap\uxml)
request=request(SoapClient.location(),soap_xml)
request.headers=SoapClient.headers()
reply=SoapClient.options.transport.send(请求)
打印(答复)
文件=[]
boundary=self.find_子字符串(reply.headers['content-type'],'boundary=“”,“”)
如果边界不是“”:
数据列表=reply.message.split(边界)
_数据的列表。pop(0)
数据列表.pop(len(数据列表)-1)

soap_body='嘿,阿卡迪,你花时间回来回答你自己的问题真是太好了!不过对我来说这听起来有点神秘。你能不能举例说明你的代码?您是按“原样”使用这种方法,还是应该将其嵌入SUD本身?谢谢