ValueError: Acquire app-only access token failed.
Hello @vgrem ,
Could you please help me I'm getting this error ValueError: Acquire app-only access token failed. while executing below mentioned code. site_url = 'https://mycompany.sharepoint.com/sites/Test' #client_id and client_secret is shared by sharepoint admin ctx = ClientContext(site_url).with_client_credentials(client_id, client_secret) doc_lib = ctx.web.default_document_library() items = ( doc_lib.items.select(["FileSystemObjectType"]) .expand(["File", "Folder"]) .get_all() .execute_query() ) for idx, item in enumerate(items): # type: int, ListItem if item.file_system_object_type == FileSystemObjectType.Folder: print( "({0} of {1}) Folder: {2}".format( idx, len(items), item.folder.serverRelativeUrl ) ) else: print( "({0} of {1}) File: {2}".format( idx, len(items), item.file.serverRelativeUrl ) )
@vgrem , Could you please help me as soon as possible. I need this very urgently
Hi,
most likely this error occurs since SharePoint app-only permissions is disabled for you tenant, per official documentation:
For new tenants, apps using an ACS app-only access token is disabled by default. We recommend using the Azure AD app-only model which is modern and more secure.
Option 1: ACS app-only access
In terms of enabling ACS app-only access token, the folowing script could be utilized: enable_app_only_authentication.py
Requires SharePoint Administrator role permissions
Option 2: Azure AD app-only access (recommended)
Refer wiki How to connect to SharePoint Online with certificate credentials for the details
Hi @vgrem ,
Thanks for your response.
I tried whatever code you were shared in option 1 . I'm attaching the result. Please suggest me what need's to be done next.
I don't have any option to use sharepoint online.. Here my use case is via pyspark code I want fetch data from snowflake and keep that file in sharepoint.
Could you please help me how can we connect to sharepoint via python code