Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

Unable to download file 404 Client Error: Not Found for url

Open Nickl55 opened this issue 2 years ago • 1 comments

I am attempting to download an Excel document from SharePoint

office365.runtime.client_request_exception.ClientRequestException: ('-2130575338, Microsoft.SharePoint.SPException', 'The file /sites/name1/Name name-2/name3/Name 4 - name/Test.xlsx' does not exist.', "404 Client Error: Not Found for url: https://company.sharepoint.com/sites/name1/_api/Web/getFileByServerRelativeUrl('%2Fsites...Test.xlsx')?$select=ServerRelativePath")

import os import tempfile from office365.runtime.auth.user_credential import UserCredential from office365.sharepoint.client_context import ClientContext from office365.sharepoint.files.file import File site_url = "https://company.sharepoint.com/sites/name1" ctx = ClientContext(site_url).with_credentials(UserCredential("[email protected]", "pass")) file_url = 'https://company.sharepoint.com/sites/name1/Name name-2/name3/Name 4 - name/Test.xlsx' download_path = os.path.join(tempfile.mkdtemp(), os.path.basename(file_url)) with open(download_path, "wb") as local_file: file = File.from_url(file_url).with_credentials(UserCredential("[email protected]", "pass")).download(local_file).execute_query()

print("[Ok] file has been downloaded into: {0}".format(download_path))

Nickl55 avatar Jan 11 '23 17:01 Nickl55

@Nickl55 did you figure out a way to debug this?

cmosguy avatar May 27 '23 14:05 cmosguy