How to connect to SharePoint in Python using username and password instead of Client credentials? What are the steps to get authorization for ******@company.com from SharePoint site?

Adithya Ramula 0 Reputation points
2023-02-20T06:46:44.8233333+00:00

I would like to know how to access SharePoint and read files by using company's username and password. And how to get authorization for my username from the site? I have fair idea for client ID ([site]/_layouts/15/AppRegNew.aspx.) Is there any process for username and password?

And also I would like to know how to access site from Python using username and password?

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
    2023-02-21T01:51:05.5833333+00:00

    Hi @Adithya Ramula

    I will recommend you to use Office365-REST-Python-Client, you can get the samples in github. The following code connect sharepoint with user credential.

    from office365.sharepoint.client_context import ClientContext
    from tests import test_site_url, settings
    
    ctx = ClientContext(test_site_url)
    ctx.with_user_credentials(settings.get('user_credentials', 'username'),
                              settings.get('user_credentials', 'password'))
    
    web = ctx.web.get().execute_query()
    print(web.url)
    
    

    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.

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.