Hi @Kompal Sithta
I will recommend you to use Office365-Rest-Python-Client to consume SharePoint Rest API and it supported App-Only Credential authentication (AuthenticationContext.ctx_auth.acquire_token_for_app(client_id, client_secret)):
Office365-REST-Python-Client 2.3.16
Here is a sample to connect SharePoint Online using App Only credential:
site_url = 'https://contoso.sharepoint.com/'
app_principal = {
'client_id': '--client-id-goes-here--',
'client_secret': '--client-secret-goes-here--',
}
context_auth = AuthenticationContext(url=site_url)
context_auth.acquire_token_for_app(client_id=app_principal['client_id'], client_secret=app_principal['client_secret'])
ctx = ClientContext(site_url, context_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Web site title: {0}".format(web.properties['Title']))
This document provide more details
https://github.com/vgrem/Office365-REST-Python-Client
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.