Download Sharepoint aspx pages as pdf using python

13 views Asked by At

I have a sharepoint client Id and secret with me.

I want to download the aspx sharepoint pages as Pdf on my local using Python.

There is an opensource lib, which will show us the page lists, office365-rest-api, but I want to download it as PDF. Any help is highly appreciated

from office365.runtime.auth.providers.acs_token_provider import ACSTokenProvider
import requests

acs_token = ACSTokenProvider(url=site_url, client_id=my_client_id, client_secret=my_secret).get_app_only_access_token()

# Get the SharePoint page contents
page_url = "https://myCompany.sharepoint.com/teams/xyz/SitePages/Home.aspx"

http_headers = {'Authorization': 'Bearer ' + acs_token.accessToken,
                'Accept': 'application/json',
                'Content-Type': 'application/json'}
data = requests.get(page_url, headers=http_headers, stream=True)
print(data)

It shows me 401 error, but I have tried with the same config on office365, I am able to download normal files(.xlsx, etc.).

May be I am doing something wrong

0

There are 0 answers