title: Grabbing files from Microsoft Teams using Python
body: <p>Teams seems to lack any native way of mirroring files to a shared directory. I'm Trying use Python (or another language but python preferred!) to either:</p>
  
  <p>a. Directly pull from microsoft teams into memory using Python to process with Pandas</p>
  
  <p>b. Copy files from teams into a shared network folder (which Python could then read in)</p>
  
  <p>I found this but can't get it to work with teams - the teams URLs don't look anything like these do. <a href="https://stackoverflow.com/questions/48424045/how-to-read-sharepoint-online-office365-excel-files-in-python-with-work-or-sch">How to read SharePoint Online (Office365) Excel files in Python with Work or School Account?</a>  </p>
  
  <p>It seems close to what I want to do though. I also found "pymsteams" on PyPi repository. <a href="https://pypi.org/project/pymsteams/" rel="noreferrer">https://pypi.org/project/pymsteams/</a> which just seems to let you send messages to Teams and nothing else? unless I misunderstand something.</p>
  
  <p><a href="https://pypi.org/project/Office365-REST-Python-Client/" rel="noreferrer">https://pypi.org/project/Office365-REST-Python-Client/</a></p>
  
  <p><a href="https://pypi.org/project/pymsteams/" rel="noreferrer">https://pypi.org/project/pymsteams/</a></p>
  
  <pre><code>from office365.runtime.auth.authentication_context
  import AuthenticationContext
  from office365.sharepoint.client_context import ClientContext
  from office365.sharepoint.file import File 
  
  url = 'https://teams.microsoft.com/l/file'
  username = 'myusername'
  password = 'mypassword'
  relative_url ='myurl'
  
  ctx_auth = AuthenticationContext(url)
  ctx_auth.acquire_token_for_user(username, password)
  </code></pre>
  
  <p>Trying to run the above code gives
      AttributeError: 'NoneType' object has no attribute 'text'</p>
  
  <p>Full stack trace: </p>
  
  <pre><code>runfile('H:/repos/foo/untitled0.py', wdir='H:/repos/foo')
  Traceback (most recent call last):
  
    File "&lt;ipython-input-35-314ab7dc63c9&gt;", line 1, in &lt;module&gt;
      runfile('H:/repos/foo/untitled0.py', wdir='H:/foo/image_ai')
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
      execfile(filename, namespace)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "H:/repos/image_ai/untitled0.py", line 10, in &lt;module&gt;
      ctx_auth.acquire_token_for_user(username, password)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\authentication_context.py", line 18, in acquire_token_for_user
      return self.provider.acquire_token()
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 57, in acquire_token
      self.acquire_service_token(options)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 88, in acquire_service_token
      token = self.process_service_token_response(response)
  
    File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 119, in process_service_token_response
      return token.text
  
  AttributeError: 'NoneType' object has no attribute 'text'
  </code></pre>