Forum Discussion

akashbam's avatar
akashbam
New Contributor
4 years ago

How to upload a file via SOAP, as an attachment using python zeep

Hi folks,

I am trying to attach a log.txt file with my createAttachment web service. I am using zeep as a client to do so but unable to do.
I tried the same using MIME but unable to do so.

 

import requests
url = "WSDL url"
payload = '''<?xml version="1.0" encoding="utf-8"?>
   <soapenv:Header/>
   <soapenv:Body>
      <ser:createAttachment>
         <sid>'''+sid+'''</sid>
         <repositoryHandle>doc:12</repositoryHandle>
         <objectHandle>cr:1306599</objectHandle>
         <description>Testing to attach document to change order</description>
         <fileName>log</fileName>
      </ser:createAttachment>
   </soapenv:Body>
</soapenv:Envelope>'''

files=[
  ('fileName',('Testing.txt',open('C:/Users/prasaka/Desktop/Testing.txt','rb'),'text/xml'))
]
headers = {
  'Content-Type': 'text/xml; charset=utf-8',
  'soapAction': 'application/soap+xml'
}
response = requests.request("POST", url, headers=headers, data={'data' : payload}, files=files)
print(response.text)
print(response.status_code)