Skip to content

Download File - Does Not Exist #346

@monkeyman51

Description

@monkeyman51

Attempted to download a file from SharePoint and returned an error message. Note, anything between square brackets is confidential information.

Error message is this:

  b'{"error":{"code":"-2130575338, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The file /sites/[site_name]/Shared Documents/[file_name].txt does not exist."}}}'

Here is the code I use:

      from office365.sharepoint.files.file import File
      from office365.sharepoint.client_context import ClientContext, ClientCredential
      
      
      main_url: str = 'https://[tenant_name].sharepoint.com/sites/[site_name]/'
      relative_url: str = '/sites/[site_name]/Shared%20Documents/text_file.txt'
      
      client_id: str = '[client_id]'
      client_secret: str = '[client_secret]'
      
      download_path: str = r'C:\Users\[user_name]\Documents\test_file.txt'
      
      ctx = ClientContext(main_url).with_credentials(ClientCredential(client_id, client_secret))
      
      response = File.open_binary(ctx, relative_url).content
      with open(download_path, 'wb') as output_file:
          output_file.write(response)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions