title: Azure sharepoint multi-factor authentication with python
body: <p>I'm trying to use python to download an excel file that is hosted in a <strong>sharepoint</strong> which is part of the <strong>Microsoft Azure platform</strong>.  The sharepoint is password protected, and I have an account and a password which I can use to login in via my browser,</p>
  
  <p>In order to authenticate with a python script I followed the method suggested in: <a href="https://stackoverflow.com/questions/55871009/sharepoint-authentication-with-python/">Sharepoint authentication with python</a>.
  Which uses the <em>O365 rest python client library</em> and goes as follows:</p>
  
  <pre><code>from office365.runtime.auth.authentication_context import AuthenticationContext
  from office365.sharepoint.client_context import ClientContext
  
  
  url = 'https://organization.sharepoint.com/sites/something/somepage.aspx'
  username = 'userx@organization.com'
  password = 'fakepass'
  
  ctx_auth = AuthenticationContext(url)
  if ctx_auth.acquire_token_for_user(username, password):
      ctx = ClientContext(url, ctx_auth)
  
  else:
      print(ctx_auth.get_last_error())
  </code></pre>
  
  <p>But I'm getting an error message back:</p>
  
  <pre><code>An error occurred while retrieving token: AADSTS50076: Due to a configuration
  change made by your administrator, or because you moved to a new location, you
  must use multi-factor authentication to access ''.
  </code></pre>
  
  <p>I do connect to this account from multiple devices (browser), and just once I was required to use MFA to log in (SMS message). Is there a way to get around this? Note that I'm not the admin of the system.</p>