I am trying to execute a POST file in a web service using CURL (which I need to use, so I cannot use twisted or anything else). The problem is that when using pyCurl webservice does not receive the file that I am sending, as in the case indicated at the bottom of the file. What am I doing wrong in my pyCurl script? Any ideas?
Many thanks.
import pycurl
import os
headers = [ "Content-Type: text/xml; charset: UTF-8; " ]
url = "http://myurl/webservice.wsdl"
class FileReader:
def __init__(self, fp):
self.fp = fp
def read_callback(self, size):
text = self.fp.read(size)
text = text.replace('\n', '')
text = text.replace('\r', '')
text = text.replace('\t', '')
text = text.strip()
return text
c = pycurl.Curl()
filename = 'my.xml'
fh = FileReader(open(filename, 'r'))
filesize = os.path.getsize(filename)
c.setopt(c.URL, url)
c.setopt(c.POST, 1)
c.setopt(c.HTTPHEADER, headers)
c.setopt(c.READFUNCTION , fh.read_callback)
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTP_VERSION, c.CURL_HTTP_VERSION_1_0)
c.perform()
c.close()
rsavu source
share