我正尝试使用pyCurl将xml文件上传到融合REST api,如下所示。 使用此方法时,我从服务器收到400错误的请求错误。我的其他用于更新页面的pyCurl代码可与REST API配合使用。请帮我解决。在过去的两天里,我都为之挣扎。
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)
非常感谢您的帮助