Forum Discussion
Bhavi2803
Sep 29, 2023Copper Contributor
Accessing file from sharepoint using python
Hi SharePoint community,
I am new to SharePoint, I need your help to read SharePoint file like excel or csv through python script from my local machine. I have used below libraries
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.files.file import File
ctx = ClientContext(SHAREPOINT_SITE).with_credentials(UserCredential(USERNAME,PASSWORD))
and used username and password for authentication purpose but every time I try to connect always getting below error
"An error occurred while retrieving token from XML response: AADSTS53003: Access has been blocked by Conditional Access policies. The access policy does not allow token issuance."
I am not sure how to fix this issue, Do I need to my org admin to provide access or is there any other API I can use to connect.
If some one has done this before please share the steps to create the connection.
Appreciate your help
Thank You
Bhawna Gupta
- First off, Python isn't really supported for this, it's better you use powershell or C#.
With that being said, your problem is authentication which means you need to make sure you've registered an app in Azure, gave it the right permission and used a token to authenticate:
You can start here:
https://learn.microsoft.com/en-us/graph/auth/auth-concepts?view=graph-rest-1.0
https://github.com/O365/python-o365#authentication