使用 atlassian-python-api 1.15.1 模块和 python 3.6
,如何下载附加在 Confluence 页面上的文件?
API 文档中的 页面操作 部分提到了一个名为 get_attachments_from_content
的 API,通过它我可以成功获取所有页面附件及其元数据的列表。下面是我可以通过打印 results
键中的其中一项所获得的示例。
我已经尝试使用 wget
模块下载附件:
fname = wget.download(base_server_name + attachment['_links']['download'])
然而,下载的文件不是页面上的文件,而是一个看起来像轻量级登录页面的大型HTML文件。此外,我不确定在这里使用 wget
是否相关,我更喜欢使用Atlassian Python API本身的解决方案,因为它可以自己管理身份验证。
"result" key:
{'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': '/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', 'operations': '', 'children': '/rest/api/content/56427526/child', 'restrictions': '/rest/api/content/56427526/restriction/byOperation', 'history': '/rest/api/content/56427526/history', 'ancestors': '', 'body': '', 'version': '', 'descendants': '/rest/api/content/56427526/descendant', 'space': '/rest/api/space/~Tim'}}
confluence.session.get(download_link)
而不是requests.get(download_link, auth=...)
。这样做可以解决在使用Confluence
的令牌认证时出现的问题。 - Christian Baumannconfluence._session.get(f'{confluence.url}/{download_link}')
并且通过令牌认证成功地运行了。在较新版本的库中,似乎session
是一个私有属性,可以作为_session
来访问。 - Overbrydconfluence._session.get(f'{confluence.url}/{download_link}')
并且在令牌验证中运行良好。在较新版本的库中,session
似乎是一个私有属性,可作为_session
使用。 - undefined