Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to download Excel file from Sharepoint

Status
Not open for further replies.

varocho

Programmer
Dec 4, 2000
238
US
I'm working on a Python (3.7) script to download an Excel (XLSX) file from within Sharepoint.

I've tried using the 'requests' module, as well as the 'Office365-REST-Python-Client' module, without success. I'm unable to open the downloaded file using Excel, the error message indicates that the file extension or the file format is invalid.

When I change the file extension to 'XLS', I see the error message '403 FORBIDDEN' within the file created by the 'requests' module. (It seems like what was actually downloaded was an error page.)

And I see the error message 'A potentially dangerous Request.Path value was detected from the client (?).' within the file created by the 'Office365-REST-Python-Client' module.

It seems the problem is that the URL for the spreadsheet I'm trying to download contains a question mark (due to there being query parameters):

...doc.aspx?sourcedoc=...&file=...&action=default

 
Turns out I needed to get the version of the SharePoint URL that specified a folder path to the file (a 'Shared_Documents' URL).

Once I got this, I was able to use the 'open_binary' method of the 'File' class to successfully download the Excel file from SharePoint.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top