'Download excel files from SharePoint document library using python
I am trying to download excel files from my work SharePoint site to a local folder using python. I have written a code to successfully authenticate into the sharepoint site.But need help in downloading the Excel files from the sharepoint document library. I am new to Python and would really appreciate your help :) Below is my code :
import urllib.request
import requests
from requests_ntlm import HttpNtlmAuth
def sharepointlogin():
site = "https://abc.sharepoint.com/site"
username = "*******"
password = "*******"
response = requests.get(site, auth=HttpNtlmAuth(username, password))
print(response.status_code)
def filedownload():
print('Downloading file')
url = 'https://abc.sharepoint.com'
urllib.request.urlretrieve(url, 'C:\Downloads\filename.xlsx')
print("File Downloaded")
print("Download complete")
sharepointlogin()
filedownload()
Solution 1:[1]
Here's a basic template code I use for downloading from my work's share-point. I think the code you posted would work.
import requests
from getpass import getpass
from requests_ntlm import HttpNtlmAuth
url = "https://share.something.com/path/file.xlsx"
session = requests.Session()
session.verify = False
username = input("Enter your username: ")
password = getpass("Enter your password: ")
session.auth = HttpNtlmAuth(username, password)
response = session.get(url)
with open(output.xlsx, wb) as f:
f.write(response.content)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hofbr |
