Hello,
I'm trying to download all attachments from confluence page using the following python code. the downloaded files are 0 kb
I changed the authorization to be using username and password
the result is the same
what could be wrong? how can I fix it?
import os, os.path
from atlassian import Confluence
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
path = r'<path for downloaded files>'
page = '<Space URL>'
confluence = Confluence(url= page, verify_ssl = False, token = "<Peronal Token>")
attachments_container = confluence.get_attachments_from_content(page_id=<page id>, start=0, limit=500)
attachments = attachments_container['results']
for attachment in attachments:
fname = attachment['title']
download_link = confluence.url + attachment['_links']['download']
r = requests.get(download_link, headers={"Authorization": "<Peronal Token>"} , verify = False)
if r.status_code == 200:
print('Downloading ' + fname + ' File!')
file = open(os.path.join(path, fname), 'wb')
file.write(r.content)
else:
print(r.status_code)
print('not downloaded')
files in the confluence
downloaded files
MyPassword = getpass.getpass()
confluence = Confluence(url= page, verify_ssl = False, username='<username>', password=MyPassword)
. . .
r = requests.get(download_link, auth=(confluence.username, confluence.password), verify = False)
I don't think the variable "download link" contains what you think it does.
You should be using a structured REST call to get the attachment, as documented at https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-attachment-content-id-get
I can't see how your code would be generating that REST call.
Thanks, Nic,
the code generates a download URL for the attachment. This is the result of printing the download link
the file is downloaded when I put the URL in the browser.
regarding the "Get attachment content", I cannot get the ID of the attachment
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, so you're using the wrong url - your script is not a browser, so it's not got all the functions you need to use a direct download.
You need to swap to using the REST api.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.