Connecting to Sharepoint

Viewed 784

I would like to CRUD files on Sharepoint. To do this I'm trying to follow the basic example on Office365-REST-Python-Client:

from office365.sharepoint.client_context import ClientContext

settings = {
    'url': 'https://*****.sharepoint.com/sites/*****',
    'user_credentials': {
        'username': '*****@gmail.com',
        'password': '*****',
    },
}

ctx = ClientContext(settings["url"]).with_user_credentials(settings.get('user_credentials').get('username'),
                                                           settings.get('user_credentials').get('password'))

web = ctx.web.get().execute_query()
print(web.properties["Url"])

which gives me an Error:

IndexError                                Traceback (most recent call last)
<ipython-input-23-c5907526ff22> in <module>
     12                                                            settings.get('user_credentials').get('password'))
     13 
---> 14 web = ctx.web.get().execute_query()
     15 print(web.properties["Url"])

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\client_object.py in execute_query(self)
     31 
     32     def execute_query(self):
---> 33         self.context.execute_query()
     34         return self
     35 

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\client_runtime_context.py in execute_query(self)
    136     def execute_query(self):
    137         if self.has_pending_request:
--> 138             self.pending_request().execute_query()
    139 
    140     def add_query(self, query, to_begin=False):

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\client_request.py in execute_query(self)
     72                 request = self.build_request()
     73                 self.beforeExecute.notify(request)
---> 74                 response = self.execute_request_direct(request)
     75                 response.raise_for_status()
     76                 self.process_response(response)

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\odata\odata_request.py in execute_request_direct(self, request)
     32     def execute_request_direct(self, request):
     33         self.ensure_media_type(request)
---> 34         return super(ODataRequest, self).execute_request_direct(request)
     35 
     36     def build_request(self):

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\client_request.py in execute_request_direct(self, request_options)
     84         :type request_options: office365.runtime.http.request_options.RequestOptions
     85         """
---> 86         self.context.authenticate_request(request_options)
     87         if request_options.method == HttpMethod.Post:
     88             if request_options.is_bytes or request_options.is_file:

D:\Anaconda\envs\hplc\lib\site-packages\office365\sharepoint\client_context.py in authenticate_request(self, request)
    151 
    152     def authenticate_request(self, request):
--> 153         self._auth_context.authenticate_request(request)
    154 
    155     def _build_modification_query(self, request):

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\auth\authentication_context.py in authenticate_request(self, request)
     82         """Authenticate request
     83         :type request: RequestOptions"""
---> 84         self._provider.authenticate_request(request)

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in authenticate_request(self, request)
     71         """
     72         logger = self.logger(self.authenticate_request.__name__)
---> 73         self.ensure_authentication_cookie()
     74         logger.debug_secrets(self._cached_auth_cookies)
     75         cookie_header_value = "; ".join(["=".join([key, str(val)]) for key, val in self._cached_auth_cookies.items()])

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in ensure_authentication_cookie(self)
     78     def ensure_authentication_cookie(self):
     79         if self._cached_auth_cookies is None:
---> 80             self._cached_auth_cookies = self.get_authentication_cookie()
     81         return True
     82 

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in get_authentication_cookie(self)
     91             user_realm = self._get_user_realm()
     92             if user_realm.IsFederated:
---> 93                 token = self._acquire_service_token_from_adfs(user_realm.STSAuthUrl)
     94             else:
     95                 token = self._acquire_service_token()

D:\Anaconda\envs\hplc\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in _acquire_service_token_from_adfs(self, adfs_url)
    134                                  headers={'Content-Type': 'application/soap+xml; charset=utf-8'})
    135         dom = minidom.parseString(response.content.decode())
--> 136         assertion_node = dom.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", 'Assertion')[0].toxml()
    137 
    138         try:

IndexError: list index out of range

Any ideas? It doesn't feel like an authentication problem.

1 Answers

It might be too late answer, but maybe it will help someone who faced with same problem and will find this question.

I had the same issue on version 2.3.9, but in version 2.1.4 there is no such problem, so you can try to use older versions.

Also there is an issue in GH repo: https://github.com/vgrem/Office365-REST-Python-Client/issues/304

Related