title: Download Sharepoint Excel File in Python
body: <p>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 <a href="https://github.com/vgrem/Office365-REST-Python-Client" rel="noreferrer">https://github.com/vgrem/Office365-REST-Python-Client</a> 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: <code>wget.download("https://shprepos.com/path/file.xlsx", local_path, bar=None)</code></p>
  
  <p>But I get a "403 FORBIDDEN" error. And I also tried with requests:</p>
  
  <pre><code>req = requests.get(ruta, auth=requests.auth.HTTPBasicAuth(username, password), headers=headers)
  with open(local_file, 'wb') as file:
      file.write(req.content)
  </code></pre>
  
  <p>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 "<a href="https://shprepos.com/path/file.xlsx" rel="noreferrer">https://shprepos.com/path/file.xlsx</a>", with the correct authentication I download the file.</p>
  
  <p>Do you know a way of downloading that file with wget using the authentication? Or am I doing something wrong in the requests.get ?</p>
  
  <p>I need a way of getting that file, using the previous authentication I did at the begining of the script:</p>
  
  <pre><code>ctx_auth = AuthenticationContext(shp_url)
  token = ctx_auth.acquire_token_for_user(username, password)
  </code></pre>
  
  <p>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!</p>
  
  <p>Thank you very much! :)</p>
  
  <p>Regards</p>