I am trying to get a sharepoint list using Office365-REST-Python-Client but the list items is returning an empty array

2022-11-22T09:23:00.223+00:00

The below is the code I am running from databricks but the items are not being returned. I have used this code successfully for another list in the same sharepoint site. This list is not empty in the sharepoint site

!pip install Office365-REST-Python-Client

import pandas as pd
from office365.runtime.auth.authentication_context import AuthenticationContext as ACX
from adal import AuthenticationContext as AC
from office365.sharepoint.client_context import ClientContext

import re
import pandas as pd

ctx_auth = ACX(siteUrl)
if ctx_auth.acquire_token_for_app(client_id=app_principal['client_id'], client_secret=app_principal['client_secret']):
ctx = ClientContext(siteUrl, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print('Authentication Successful for: ',web.properties['Title'])

list_object = ctx.web.lists.get_by_title('Glen Lyon IEC Constants Table')

items = list_object.get_items()

ctx.load(items)

ctx.execute_query()

for item in items:

print("Item title: {0}".format(item.properties["Title"]))
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-11-23T02:46:44.97+00:00

    Hi @Kynaston, Matt (KUBRICK GROUP LIMITED)
    Empty results usually means that required permissions are missing. To query SharePoint list items, depending on the list type the following permission scope needs to be specified:
    For SharePoint List: Sites.Read.All or Sites.ReadWrite.All
    For SharePoint Library: Files.Read.All or Files.ReadWrite.All

    You need to check the permissions of the list items too. Some list items will have unique permissions and that makes other users unable to access them. Please refer to the following document
    https://support.microsoft.com/en-gb/office/customize-permissions-for-a-sharepoint-list-or-library-02d770f3-59eb-4910-a608-5f84cc297782

    Also the following setting might also cause the item only available for the creator
    263301-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.