OFFICE365-REST-python-client to connect to sharepoint API, acquire_token_for_user failure

Viewed 8

While trying to use OFFICE365-REST-python-client to connect to sharepoint site keep getting error while trying acquire_token_for_user

Error messages out as "list index out of range"

Here is simple code I am trying to execute from github example

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

url = "https:/@company.sharepoint.com/sites/channel"
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user("username", "password")
ctx = ClientContext(url, ctx_auth)
response = File.open_binary(ctx, "/Shared Documents/Reference.xlsx")
with open("./User Guide.docx", "wb") as local_file:
    local_file.write(response.content)

Error I am getting

IndexError                                Traceback (most recent call last)
c:\Users\SP70873\OneDrive - Panasonic Corporation of North America\Accruals\Reratings\Rerating_Workbook.ipynb Cell 4 in <cell line: 7>()
      5 url = "https://pcus1.sharepoint.com/sites/LogisticsPlanningTeam"
      6 ctx_auth = AuthenticationContext(url)
----> 7 ctx_auth.acquire_token_for_user("Shriram.Poudel@us.panasonic.com", "Ragekornslipknot143")   
      8 ctx = ClientContext(url, ctx_auth)
      9 response = File.open_binary(ctx, "/Shared Documents/Reference.xlsx")

File c:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\authentication_context.py:75, in AuthenticationContext.acquire_token_for_user(self, username, password, browser_mode)
     66 """Acquire token via user credentials
     67 Status: deprecated!
     68 
   (...)
     71 :type browser_mode: str
     72 """
     73 self._provider = SamlTokenProvider(url=self.url, username=username, password=password,
     74                                    browser_mode=browser_mode)
---> 75 return self._provider.ensure_authentication_cookie()

File c:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py:84, in SamlTokenProvider.ensure_authentication_cookie(self)
     82 def ensure_authentication_cookie(self):
     83     if self._cached_auth_cookies is None:
---> 84         self._cached_auth_cookies = self.get_authentication_cookie()
     85     return True
...
    145         'serviceTokenUrl': self._sts_profile.security_token_service_url,
    146         'assertion_node': assertion_node
    147     })

IndexError: list index out of range
0 Answers
Related