Hello Brethren,
I am trying to upload an xml file to confluence REST API using pyCurl as below. While using this I get a 400 Bad request error from the server. My other pyCurl code to update the page works fine with the REST API. Please help me resolve. Below is the code
def upload_files_to_confluence(pageId,filepath):
b = io.BytesIO()
c = pycurl.Curl()
url= config['RESTURLS']['CONFURL'] +"rest/api/content/"+pageId+"/child/attachment"
c.setopt(pycurl.URL, url)
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.CAINFO, certifi.where())
c.setopt(pycurl.PROXY, config['CERTIFICATES']['PROXY'])
c.setopt(pycurl.SSLKEY, config['CERTIFICATES']['SSLKEYPATH'])
c.setopt(pycurl.SSLCERT, config['CERTIFICATES']['SSLCERTPATH'])
c.setopt(pycurl.USERPWD, config['AUTH']['USERNAME'] + ':' + config['AUTH']['PASSWORD'])
c.setopt(pycurl.POST,1)
c.setopt(pycurl.HTTPHEADER,['Content-type: text/xml; charset=UTF-8','X-Atlassian-Token : no-check','Accept-Language: en'])
c.setopt(pycurl.HTTPPOST, [("testResults", (c.FORM_FILE, filepath,pycurl.FORM_CONTENTTYPE,"text/xml",pycurl.FORM_FILENAME, "testResult1"))])
c.setopt(c.VERBOSE, True)
c.perform()
c.close()
response_body = b.getvalue().decode('UTF-8')
print(response_body)