I am trying to download all the files within 4 (or more) subfolders which is inside the main folder named 'Reports' in Sharepoint.

I used the following code:

url = 'https://HAHA.sharepoint.com/sites/Forms/Reports/'
import getpass
domain = 'HAHA.sharepoint.com' 
user = getpass.getuser() 
pwd = getpass.getpass(prompt='What is your windows AD password?')

import requests
from requests_ntlm import HttpNtlmAuth
from urllib.parse import unquote
from pathlib import Path

filename = unquote(Path(url).name)
response = requests.get(url, auth=HttpNtlmAuth(f'{domain}\\{user}', pwd ))

for file in filename:
        with open(filename, 'wb') as local_file:

However, I get an error OSError: [Errno 22] Invalid argument: 'AllItems.aspx?FolderCTID=0x0120001B8F714072E1184781C4A5E4969E4CC9&id=/Reports'

Would anyone help me fix this? Thank you. I'm wondering if this code is specifically downloading one file. I want to download the whole folder and its sub-folders and the files within the subfolders.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.