I want to download a file from my sharepoint 2016 server using Python.
I am using the requests module, but if another module is better, can use that one instead.
from requests.auth import HTTPBasicAuth
import requests
headers = {'accept': 'application/json;odata=verbose'}
auth = HTTPBasicAuth("username", "password")
r = requests.get("https://example.sharepoint.com/_api/web", auth=auth, headers=headers)
But my request gets redirected to my https://example.sharepoint.com/my.policy page with HTML data that contains the following:
Session Expired/Timeout Due to user inactivity, your session expired. Click the following link to start a new session.
I also tried:
from requests_ntlm import HttpNtlmAuth
auth = HttpNtlmAuth("username", "password")
r = requests.get("https://example.sharepoint.com/_api/web", auth=auth, headers=headers)
but got the same redirect to .
This seems similar to the authentication prompt issue described in this SE: SharePoint 2016 - ADFS - persistent cookie - office client integration - authentication prompt
I think I need to include an authentication cookie with my request somehow, but I could be wrong. Any idea what the authentication/persistant cookie object looks like?