最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Download Confluence Pages as PDFs via API using Python - Stack Overflow

programmeradmin0浏览0评论

I’m trying to download Confluence pages in a space as PDFs using the Confluence API and a Python script. However, I am unable to download the PDF despite manually being able to export pages via the browser.

Goal: Download all pages in a Confluence space (in a hierarchy) as PDF files using Python and an API key.

What I’ve Tried: Basic Authentication via API I used the following Python script to send a GET request to the PDF export endpoint:

import requests
from requests.auth import HTTPBasicAuth

# Configuration
base_url = ";
space_key = "SPACE"
username = "[email protected]"
api_token = "YOUR_API_TOKEN"  # replace with your actual API token
page_id = "463***765"

# Create the URL for PDF export
url = f"{base_url}/spaces/{space_key}/pdfpageexport.action?pageId={page_id}"

# Headers
headers = {
    "X-Atlassian-Token": "no-check"
}

# Send the request using basic authentication
response = requests.get(url, auth=HTTPBasicAuth(username, api_token), headers=headers)

# Check if the request was successful
if response.status_code == 200:
    print("Request was successful!")
    # Save the file (optional)
    with open('page_export.pdf', 'wb') as file:
        file.write(response.content)
else:
    print(f"Request failed with status code: {response.status_code}")
    print(response.text)

The Issue: I am unable to download the PDF using Python, even though the browser-based export works fine. I am unsure whether I'm missing some required headers I would like to automate this process to download all pages from a Confluence space in a hierarchical structure

发布评论

评论列表(0)

  1. 暂无评论