Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用oauth1和python调用confluence api时发布附件?_Python_Attachment_Confluence_Oauth 1.0a - Fatal编程技术网

如何在使用oauth1和python调用confluence api时发布附件?

如何在使用oauth1和python调用confluence api时发布附件?,python,attachment,confluence,oauth-1.0a,Python,Attachment,Confluence,Oauth 1.0a,我成功地用oauth1更新了调用confluence api的confluence页面。但我无法发布附件。我查看了多个博客,但找不到任何解决方案。我通过使用pythons库“requests_oauthlib”解决了这个问题。下面是我用来更新confluence上附件的代码片段 from requests_oauthlib import OAuth1 class Confluence_Page_Update(): def __init__(self, file__with_path):

我成功地用oauth1更新了调用confluence api的confluence页面。但我无法发布附件。我查看了多个博客,但找不到任何解决方案。

我通过使用pythons库“requests_oauthlib”解决了这个问题。下面是我用来更新confluence上附件的代码片段

from requests_oauthlib import OAuth1

class Confluence_Page_Update():
    def __init__(self, file__with_path):
        self.client_key = 'abcxyz'
        self.client_secret = ''
        self.key = open("/opt/SP/apps/confluence_auto_update/rsa.pem").read()
        self.resource_owner_key = 'jasnjdnajsndjandjnaj'
        self.resource_owner_secret = 'ajsndjansjdnajdnja'
        attachment = open(file__with_path, 'rb')
        filename = ntpath.basename(file__with_path)
        self.files = {'file': (filename, attachment, 'application/octet-stream')}


def send_attachment(self, pageid, attachmentid):
        headers = {"X-Atlassian-Token": "nocheck"}
        oauth = OAuth1(self.client_key, client_secret=self.client_secret,
                       resource_owner_key=self.resource_owner_key,
                       resource_owner_secret=self.resource_owner_secret,
                       signature_type='auth_header', rsa_key=self.key, signature_method='RSA-SHA1')
        r = requests.post(url="https://cps.confluence.abc.com/rest/api/content/" + pageid + "/child/attachment/" + attachmentid + "/data", auth=oauth, files=self.files, headers=headers)
        print(r.status_code)