question

sfmapper-2967 avatar image
0 Votes"
sfmapper-2967 asked JagadeeshLankiReddy-5847 edited

How to download a XLS from Teams/SharePoint using Python

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)

office-teams-app-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@sfmapper-2967

As we are mainly responsible for general issue of Microsoft Teams, your question which is involved in development is not supported by us, I would remove the office-teams-windows-itpro tag and add the office-teams-app-dev tag. Hope you get better response.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



0 Votes 0 ·

1 Answer

JagadeeshLankiReddy-5847 avatar image
0 Votes"
JagadeeshLankiReddy-5847 answered JagadeeshLankiReddy-5847 edited

Re: How to download a XLS from Teams/SharePoint using Python

All the files in Teams are saved in Share point. All those files can be downloaded using SharePoint API. The second option can be using the Graph API.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.