Hello,
I am attempting to download a xls file from our Teams shared files. I have gotten it to work most of the way but am having two issues.
The first, the resulting downloaded xls is always corrupted and is only 1kb in size.
The second, I cant figure out how to dictate the directory where the xls is copied to. It currently copies it to the same location as the .py file.
Any help would be appreciated.
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.files.file import File
site_url = "https://[our co].sharepoint.com/teams/[our teams channel]"
library = "/Shared Documents/"
filename = "test.xlsx"
pathToFile = library + filename
app_principal = {
'client_id': '[our client id]',
'client_secret': '[our client secret]',
}
ctx_auth = AuthenticationContext(site_url)
ctx_auth.acquire_token_for_app(client_id=app_principal['client_id'], client_secret=app_principal['client_secret'])
ctx = ClientContext(site_url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
fileToRetrieve = File.open_binary(ctx, pathToFile)
output = open(filename, 'wb').write(fileToRetrieve.content)