使用atlassian-python-api 1.15.1模块,python 3.6
如何下载附加到 Confluence 页面的文件?
API 文档的页面操作部分提到了一个 API get_attachments_from_content
,通过它我可以成功获取所有页面附件的列表及其元数据。在这个问题的末尾有一个例子,我可以通过打印results
密钥中的一个项目来获得什么。
我已经尝试过使用该wget
模块下载附件:
fname = wget.download(base_server_name + attachment['_links']['download'])
但是,下载的文件不是页面上的文件,而是我有一个看起来像一个轻登录页面的大 HTML 文件。另外,我不确定 usingwget
在这里是否相关,我更喜欢使用 atlassian python API 本身的解决方案,因为它自己管理身份验证。
“结果”键:
{'id': '56427526', 'type': 'attachment', 'status': 'current', 'title': 'main.c', 'metadata': {'mediaType': 'application/octet-stream ', 'labels': {'results': [], 'start': 0, 'limit': 200, 'size': 0, '_links': {'self': ' https://foo.bar. com/confluence/rest/api/content/56427526/label '}}, '_expandable': {'currentuser': '', 'properties': '', 'frontend': '', 'editorHtml': ''} }, 'extensions': {'mediaType': 'application/octet-stream', 'fileSize': 363, 'comment': ''}, '_links': {'webui': '/pages/viewpage.action? pageId=14648850&preview=%2F14648850%2F56427526%2Fmain.c', '下载': '/download/attachments/14648850/main.c?version=1&modificationDate=1580726185883&api=v2', 'self': ' https://foo.bar. com/confluence/rest/api/content/56427526'}, '_expandable': {'container': '/rest/api/content/14648850', '操作': '', 'children': '/rest/api/content/56427526/child', 'restrictions' :'/rest/api/content/56427526/restriction/byOperation','历史':'/rest/api/content/56427526/history','祖先':'','body':'','版本' :'','后代':'/rest/api/content/56427526/descendant','空间':'/rest/api/space/~Tim'}}