i am trying to download an xlsx file from sharepoint but still getting an error that the url for the file is not valid
i get the url form here
but i get this error:
office365.runtime.client_request_exception.ClientRequestException: ('-2130575338, Microsoft.SharePoint.SPException', "404 Client Error: Not Found for url: <the url here>"
here is my code:
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
# SharePoint site URL
site_url = 'https://<company>.sharepoint.com'
file_url = "<path to the file>/Professional%20Services%20employees.xlsx"
# Credentials for SharePoint authentication
username = '<username>'
password = '<password>'
user_credentials = UserCredential(username,password)
ctx = ClientContext(site_url).with_credentials(user_credentials)
with open("test.xlsx", "wb") as local_file:
file = ctx.web.get_file_by_server_relative_url(file_url).download(local_file).execute_query()
print(file)
print("[Ok] file has been downloaded into")