Office 365 REST Python Client - Unable to get author name of Sharepoint file

Hello Everyone.

I’m Using Office 365 REST Python Client package to connect to Sharepoint and pull the File metadata mainly “Author Name”.

I’m using the following code to achieve this.

conn = ClientContext(sharepoint_url_site).with_credentials(UserCredential(username , password))

target_folder_url = sharepoint_doc_library+'Test/Bulk Upload Test' 
folder = conn.web.get_folder_by_server_relative_url(target_folder_url)

folder.expand(['listAllFields']).get().execute_query()


However, The last line of code returns the following error.
“List index out of range”

I have tried searching online and none of the fixes mentioned have worked.

Any help would be appreciated.

Thanks in Advance.

Please post the full traceback when the error occurs.

IndexError                                Traceback (most recent call last)
<ipython-input-32-d6db401dfafe> in <module>
----> 1 folder.expand(['listAllFields']).get().execute_query()

C:\Anaconda\lib\site-packages\office365\runtime\client_object.py in execute_query(self)
     42         :type self: T
     43         """
---> 44         self.context.execute_query()
     45         return self
     46 

C:\Anaconda\lib\site-packages\office365\runtime\client_runtime_context.py in execute_query(self)
    144     def execute_query(self):
    145         """Submit request(s) to the server"""
--> 146         self.pending_request().execute_query()
    147 
    148     def add_query(self, query):

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

C:\Anaconda\lib\site-packages\office365\runtime\odata\request.py in execute_request_direct(self, request)
     34         """
     35         self._build_specific_request(request)
---> 36         return super(ODataRequest, self).execute_request_direct(request)
     37 
     38     def build_request(self, query):

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

C:\Anaconda\lib\site-packages\office365\sharepoint\client_context.py in authenticate_request(self, request)
    236 
    237     def authenticate_request(self, request):
--> 238         self.authentication_context.authenticate_request(request)
    239 
    240     def _build_modification_query(self, request):

C:\Anaconda\lib\site-packages\office365\runtime\auth\authentication_context.py in authenticate_request(self, request)
     88         :type request: office365.runtime.http.request_options.RequestOptions
     89         """
---> 90         self._provider.authenticate_request(request)

C:\Anaconda\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in authenticate_request(self, request)
     75         """
     76         logger = self.logger(self.authenticate_request.__name__)
---> 77         self.ensure_authentication_cookie()
     78         logger.debug_secrets(self._cached_auth_cookies)
     79         cookie_header_value = "; ".join(["=".join([key, str(val)]) for key, val in self._cached_auth_cookies.items()])

C:\Anaconda\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in 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
     86 

C:\Anaconda\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py in get_authentication_cookie(self)
     95             user_realm = self._get_user_realm()
     96             if user_realm.IsFederated:
---> 97                 token = self._acquire_service_token_from_adfs(user_realm.STSAuthUrl)
     98             else:
     99                 token = self._acquire_service_token()

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

IndexError: list index out of range

I know nothing about this client. But reading the traceback …

tries to get the first element of the list returned by the .get... call. The error indicates that the list is empty. You need to think about what, if anything, you did wrong for the list to be empty.

One possibility is that in your code you should wrap

with try:... except IndexError: and handle the empty list situation however you want.

This looks like the SAML is not as expected by the code.

Is there a way to get the XML data to examine?

I suggest you contact the authors of the code to ask them for help.