Forum Discussion

akashbam's avatar
akashbam
New Contributor
3 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)
    • akashbam's avatar
      akashbam
      New Contributor

      Thanks richie for your response.

       

      Well, I want to attach a file with code(python). I am calling soap API and binding it with with web service(createAttachment) which accepts parameter as 

       
      import zeep
      client.service.createAttachment(sid=788139782, repositoryHandle='doc:1002', objectHandle='cr:1306591599', description='Test file', fileName='Test Data')
       
      I'm able to attach a file using soapUI but want to do the same using python.
       
      Thanks,
      Akash