title: How to Download a PDF File from Online SharePoint using python?
body: <p><strong>How to Download a PDF File from Online SharePoint using python?</strong></p>
  <p><strong>I've tried this code: but whenever I try this it downloads a broken file</strong></p>
  <pre><code>from office365.runtime.auth.authentication_context import AuthenticationContext
  from office365.sharepoint.client_context import ClientContext
  from office365.sharepoint.files.file import File
  
  url = &quot;SharePointFilePath&quot;
  username= &quot;Username&quot;
  password= &quot;Password&quot;
  
  ctx_auth = AuthenticationContext(url)
  ctx_auth.acquire_token_for_user(username, password)   
  ctx = ClientContext(url, ctx_auth)
  response = File.open_binary(ctx, &quot;SharepointURL&quot;)
  with open(&quot;file.pdf&quot;,&quot;wb&quot;) as local_file:
      local_file.write(response.content)
  </code></pre>