Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to import Confluence-rest-library and download attachment in Confluence

Celine January 30, 2019

Hi,

I'm trying to download attachments from Confluence by confluence-rest-library.  And found there is a get_attachments function in confluence-rest-library. However, I'm not very sure how to use this library.

1. When install the package, besides the 'Successfully installed confluence-rest-library-1.0.0' message, I also get several 'Using cached..', 'Requirement already satisfied' message. So I'm not sure whether the package is installed completely successful or not. I tried to uninstall and reinstall it, but still get same messages.

2. in the readme for this library, saying to import the library, the syntax is

" from confluence.client import Confluence
with Confluence('https://site:8080/confluence', ('user', 'pass')) as c:
pages = c.search('ID=1')"

What does 'c:' mean? and what should be put in the search(??)? 

I've double checked the package is in the same path as my other python packages, such as requests which can be import directly by 'import requests'. 

3. Has anyone had the same import problems? Or has any suggestions in how to download the Confluence attachments to local? Please advise.

Thanks,

Xilin

 

1 answer

0 votes
Celine January 30, 2019

Update:

I seem to be able to connect to Confluence by:

confluence = Confluence('https://site:8080/confluence', ('user', 'pass'))').

 

I tried to get attachment with the get_attachment function:

attachment = confluence.get_attachments(content_id='XXX', expand='None')

print('attachment =',attachment)
print ('attachment type =',type(attachment))

then I get the result as:

attachment = <generator object Confluence._get_paged_results at 0x031413C0>
attachment type = <class 'generator'>

However, when I try to print the attachment generator by:

print (next(attachment))

I got the following error messages:

File "C:\Users\...\Python\Python36-32\lib\site-packages\confluence\clien
t.py", line 111, in _get_paged_results
    Confluence._handle_response_errors(path, params, response)
  File "C:\Users\...\Python\Python36-32\lib\site-packages\confluence\clien
t.py", line 78, in _handle_response_errors
    raise ConfluenceResourceNotFound(path, params, response)
confluence.exceptions.resourcenotfound.ConfluenceResourceNotFound: Resource was not found at path content/XXX/child/attachment or the user has insufficient permissions

 

The url I put in is 'https://site:8080/confluence'.

The confluence rest api add it to 'https://site:8080/confluence/rest/api'.

The get_attachment function add it to 'https://site:8080/confluence/rest/api/content/XXX/child/attachment'.

however, it is an invalid link even when I try it in browser manually. Error message is "The website declined to show this webpage. Most likely causes: This website requires you to log in.". I was logging in when trying manually, and also added correct username and password when running the script.

 

Anyone has any clue what is the right url to access the attachment? Or is there any mistake when using this api in the above code?

 

Thanks,

Celine


 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events