I'm trying to download an Excel file from a SharePoint repository using a Python script. I'm using the Office365-Rest-Python-Client as defined in the examples at https://github.com/vgrem/Office365-REST-Python-Client and I have access to all the files/directories I need. The problem comes when I want to download any of the files. I've tried several approaches, but none of them works: wget.download("https://shprepos.com/path/file.xlsx", local_path, bar=None)
But I get a "403 FORBIDDEN" error. And I also tried with requests:
req = requests.get(ruta, auth=requests.auth.HTTPBasicAuth(username, password), headers=headers)
with open(local_file, 'wb') as file:
file.write(req.content)
And with this code I'm getting the webpage, not the excel file, and I don't understan why, because if I access the url "https://shprepos.com/path/file.xlsx", with the correct authentication I download the file.
Do you know a way of downloading that file with wget using the authentication? Or am I doing something wrong in the requests.get ?
I need a way of getting that file, using the previous authentication I did at the begining of the script:
ctx_auth = AuthenticationContext(shp_url)
token = ctx_auth.acquire_token_for_user(username, password)
Do you know a way of doing this? Maybe the python Client has a method for downloading the files but I can't find it!
Thank you very much! :)
Regards