title: How to download a Confluence page attachment with Python?
body: <p>With the <a href="https://pypi.org/project/atlassian-python-api/" rel="nofollow noreferrer">atlassian-python-api 1.15.1</a> module and <code>python 3.6</code> <strong>how can I to download a file attached to a Confluence page ?</strong> </p>
  
  <p>The <a href="https://atlassian-python-api.readthedocs.io/en/latest/confluence.html#page-actions" rel="nofollow noreferrer">page actions</a> section of the API documentation mentions an API <code>get_attachments_from_content</code>, with which I can successfully obtain a list of all page attachments, with their metadata. There's an example at the end of this question of what I can obtain by printing one of the items in the <code>results</code> key.</p>
  
  <p>What I already tried is to use the <code>wget</code> module to downloaad the attachment:</p>
  
  <pre><code>fname = wget.download(base_server_name + attachment['_links']['download'])
  </code></pre>
  
  <p>However, the downloaded file is not the one on the page, instead I have a large HTML file which looks like a light login page. Also, I'm not sure using <code>wget</code> is relevant here, I'd prefer a solution with the atlassian python API itself, as it's managing authentication by itself. </p>
  
  <p><strong>"result" key:</strong></p>
  
  <blockquote>
    <p>{'id': '56427526', 'type': 'attachment', 'status': 'current', 'title': 'main.c', 'metadata': {'mediaType': 'application/octet-stream', 'labels': {'results': [], 'start': 0, 'limit': 200, 'size': 0, '_links': {'self': '<a href="https://foo.bar.com/confluence/rest/api/content/56427526/label" rel="nofollow noreferrer">https://foo.bar.com/confluence/rest/api/content/56427526/label</a>'}}, '_expandable': {'currentuser': '', 'properties': '', 'frontend': '', 'editorHtml': ''}}, 'extensions': {'mediaType': 'application/octet-stream', 'fileSize': 363, 'comment': ''}, '_links': {'webui': '/pages/viewpage.action?pageId=14648850&amp;preview=%2F14648850%2F56427526%2Fmain.c', 'download': '/download/attachments/14648850/main.c?version=1&amp;modificationDate=1580726185883&amp;api=v2', 'self': '<a href="https://foo.bar.com/confluence/rest/api/content/56427526" rel="nofollow noreferrer">https://foo.bar.com/confluence/rest/api/content/56427526</a>'}, '_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'}}</p>
  </blockquote>