vgrem / Office365-REST-Python-Client

Microsoft 365 & Microsoft Graph Library for Python
MIT License
1.29k stars 332 forks source link

ValueError: Acquire app-only access token failed. #816

Open pushpape12 opened 7 months ago

pushpape12 commented 7 months ago

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 ) )

pushpape12 commented 7 months ago

@vgrem , Could you please help me as soon as possible. I need this very urgently

vgrem commented 7 months ago

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

pushpape12 commented 7 months ago

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 sharepoint1

avabhishiek commented 2 weeks ago

Hey @pushpape12 @vgrem Was a solution found for the above issue? I am facing the exact same issue and have ACS app-only token enabled on tenant (using the script above)

Sai-Prathik commented 5 days ago

Hi @pushpape12 @vgrem Has anyone found a solution for this issue? While the above script prints an ACS app-only access token already enabled, I'm still unable to solve this issue. Upon checking, I see that get_property("DisableCustomAppAuthentication") is returning None. Is this the intended behaviour? Another quick solution would be much appreciated.

test