Caml Query not working using Python on sharepoint Online

I am using Python to get the data from share point. I want to extract particular rows or data which has Status = "Submitted".

For that i have written below code but i am not sure why am i getting error.


from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.caml.caml_query import CamlQuery
from office365.runtime.auth.user_credential import UserCredential

baseurl = 'https://my.org.com'
basesite = '/teams/ia/Powerappsdatabase/' # every share point has a home.
siteurl = baseurl + basesite 
print(siteurl)

sp_list = "HCFM_Projects"
ctx = ClientContext(siteurl).with_credentials(UserCredential("name@org.com", "password"))
sp_lists = ctx.web.lists
s_list = sp_lists.get_by_title(sp_list)

query_text = 
<Where>
        <Eq>
            <FieldRef Name="Status" />
            <Values>
                <Value Type="Choice">Submitted</Value>
                
            </Values>
        </Eq>
</Where>


caml_query = CamlQuery.parse(query_text)
items = s_list.get_items(caml_query)
ctx.load(items) 
ctx.execute_query()

But I am getting error ClientRequestException: ('-2130575252, System.Runtime.InteropServices.COMException', 'The security validation for this page has timed out. Click Back in your Web browser, refresh the page, and try your operation again.', "403 Client Error: FORBIDDEN for url: https://my.org.com/teams/ia/Powerappsdatabase/_api/Web/lists/GetByTitle('HCFM_Projects')/GetItems")



Read more here: https://stackoverflow.com/questions/68486066/caml-query-not-working-using-python-on-sharepoint-online

Content Attribution

This content was originally published by Akshi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: