0

I am trying to create a python code that will take 10+ excel tables of data, and append them into a single table. I'd also like to clear the destination table contents prior to doing this, so every time the code runs it will provide updated values from the 10 files.

I've tried to access these files within SharePoint but everytime I do this, the file returns as corrupt. I'm in the first stages of this code, but I'd like for it to at least be able to pull the data into Python for me to start manipulating

import requests
from requests.auth import HTTPBasicAuth
file = "https://ts.company.com/:x:/r/sites/XXXX/Shared%20Documents/General/Folder/XXXX.xlsx?d=w2ef8664034b243c89400e549b0cbf36d&csf=1&e=b5mA10"
username = 'robert.xxxxx@company.com'
password = 'password123'

resp=requests.get(file, auth=HTTPBasicAuth(username, password))
output = open('test.xlsx', 'wb')
output.write(resp.content)
output.close()
RCarmody
  • 712
  • 1
  • 12
  • 29
  • I'd try throwing in a "print(resp.content)" and see what you're getting back from that website. – Chris Curvey Jul 22 '19 at 22:47
  • I am getting a 403 FORBIDDEN – RCarmody Jul 23 '19 at 01:54
  • You need to solve that 403 error first. What's happening is that the text of the error message is being stored in your XLSX file, and when Excel tries to open the file, it says "this is not an XLSX file!" – Chris Curvey Jul 23 '19 at 15:13
  • If I am navigating to SharePoint, copying the link, and inserting my normal credentials - why would this still be forbidden? – RCarmody Jul 23 '19 at 17:42
  • I'm not a SharePoint guy, but I'd assume that SharePoint wants a different kind of authentication than HttpBasicAuth. Ahh, maybe this is it? https://stackoverflow.com/questions/20945822/how-to-access-a-sharepoint-site-via-the-rest-api-in-python – Chris Curvey Jul 25 '19 at 12:49

0 Answers0