Forums

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

Download Confluence pages in pdf formats using Python

Rajat Singh May 3, 2020

I tried using requests module and atlassian api but always ending up in having another link to download page. I used flyingpdf url in the modules. The code I used is :

import requests

url1 = "https://confluence.xxx.com/confluence/spaces/flyingpdf/pdfpageexport.action?pageId=12345667"

with requests.Session() as session:
session.auth = HTTPBasicAuth('username', 'password')
myfile = session.get(url1, verify=False)

print(myfile.url)
open("C:\\Users\\%current_user%\\Downloads\\trying" + ".pdf", 'wb').write(myfile.content)

 

Also, when I am using get function in requests module it not even prompting for authentication (tried both ways). The content resulting in myfile.content is some javascript.

1 answer

0 votes
Gonchik Tsymzhitov
Community Champion
May 3, 2020
Rajat Singh May 3, 2020

I tried that method also but the resulting pdf is also containing javascript redirecting me to the company's login page. Does it have to do something with the login interface or with ssl verification (currently giving as False) ?

I also tried without giving the authentication credentials but still giving the same result. In short if I am trying with credentials also, the get method or the confluence get_page_as_pdf method is simply bypassing the authentication process.

ian.lamotte-kerr
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 20, 2020

Did you ever work this out by chance? I am hitting teh exact same problem.

Rajat Singh July 20, 2020

Yeah. In my case I wanted to access my company's confluence pages which are protected by siteminder authentication. So, I had to create a session with Siteminder STS ( Secure token Service) with a specific company provided URL and login into that. After this process the rest is very easily done by using requests module or using Confluence API.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events