我如何在调用 confluence api 时使用带有 python 的 oauth1 post 附件?
How do i post an attachment while calling confluence api using oauth1 with python?
我成功更新了使用 oauth1 调用 confluence api 的 confluence 页面。但是我无法 post 附件。我查看了多个博客,但找不到任何解决方案。
我能够通过使用 pythons 库解决这个问题 "requests_oauthlib"。下面是我用于更新合流附件的代码片段。
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)
我成功更新了使用 oauth1 调用 confluence api 的 confluence 页面。但是我无法 post 附件。我查看了多个博客,但找不到任何解决方案。
我能够通过使用 pythons 库解决这个问题 "requests_oauthlib"。下面是我用于更新合流附件的代码片段。
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)