logo
search
Permission & Access Issues

How to Fix SharePoint API 401 Errors with Python and MSAL

Aamir Naveed AkramAamir Naveed Akram Oct 16, 2026 870 views

Question details

Users need to resolve an authentication failure when calling the SharePoint API programmatically using a Python script and MSAL.

How to Fix SharePoint API 401 Errors with Python and MSAL
Product
Microsoft SharePoint / MSAL
Device & OS
not provided
Scenario
Accessing SharePoint resources programmatically using a Python script authenticated via the Microsoft Authentication Library (MSAL).
Observed behavior
The API request fails, returning an HTTP 401 Unauthorized error along with an ID3035 error code.
Before you start

Ensure you have administrative access to your Microsoft Entra ID (formerly Azure AD) portal to verify application registrations and API permissions.

Solution 1Recommended

Verify Azure App Permissions and Token Audience

Ensure your application has the correct API permissions and is requesting an MSAL token for the appropriate SharePoint resource.

A common cause of the ID3035 error is requesting an access token for the Microsoft Graph API but attempting to use it on a SharePoint REST endpoint, or lacking the necessary application permissions.

1
Access App Registration

Log in to the Microsoft Entra ID admin center, navigate to 'App registrations', and select your specific Python application.

2
Check API Permissions

Go to 'API permissions' and verify that 'Sites.ReadWrite.All' (or your required scope) is added under the SharePoint API section, not just Microsoft Graph.

3
Verify Admin Consent

Check the status column next to the permissions. Ensure a tenant administrator has clicked 'Grant admin consent' so the status displays a green checkmark.

4
Update Python Scope

In your Python MSAL configuration, ensure the scope array uses your specific SharePoint tenant URL (e.g., ['https://yourtenant.sharepoint.com/.default']).

Verify Azure App Permissions and Token Audience
Client Credentials Flow: When using the Client Credentials flow (daemon apps without a user), application-level permissions always require tenant administrator consent to function.
Free Microsoft Office alternative

Looking for a Simpler Way to Manage Documents?

While troubleshooting complex Microsoft 365 and SharePoint API errors, you might be looking for a more streamlined, hassle-free way to manage and collaborate on documents. WPS Office offers a lightweight, highly compatible alternative to Microsoft Office, complete with robust built-in cloud storage.

  1. 1. Download and Install: Download WPS Office from the official website and run the installer.
  2. 2. Sign In for Cloud Access: Open WPS Office and sign in to activate your free cloud storage workspace.
  3. 3. Collaborate Instantly: Upload your documents to WPS Cloud to seamlessly share and collaborate with your team.
Seamless compatibility with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx) without complex setups.Built-in cloud storage (WPS Cloud) for easy document sharing and team collaboration without needing API configuration.Lightweight software that runs smoothly on Windows, Mac, Linux, iOS, and Android.Free to use with a familiar, user-friendly interface that requires zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

What does error ID3035 mean in SharePoint API?

Error ID3035 typically indicates that the access token provided in your HTTP API request is invalid, expired, or does not have the correct audience or permissions required for the requested SharePoint resource.

How do I check my MSAL token audience in Python?

You can decode the JWT access token generated by MSAL using a Python library like PyJWT or an online tool like jwt.ms. Check the 'aud' (audience) claim to ensure it matches your SharePoint tenant URL rather than Microsoft Graph.

Why am I getting a 401 error even after granting API permissions in Azure?

If you are using the Client Credentials flow, adding the permissions is not enough. You must ensure that a tenant administrator has explicitly clicked the 'Grant admin consent' button in the Azure portal for those permissions to become active.

Does WPS Office provide alternatives for Python automation?

Yes, WPS Office provides secondary development interfaces and macros that enterprise users can leverage to automate document processing workflows, offering an alternative to complex Microsoft Office and SharePoint API integrations.