Share via

Python - Sharepoint Integration

KKS 5 Reputation points
2025-06-10T23:27:32.64+00:00

Hi Team,

I have MS work a/c with un/pw & MFA (Authenticator setup). I would like to write a python scripts running on my local machine to upload few files to Sharepoint - but it fails because direct python with un/pw doesn't works automatically. My intention is to move these scripts to a server in future - Is there any way to do? if not, any alternative?

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

1 answer

Sort by: Most helpful
  1. Teddie-D 14,700 Reputation points Microsoft External Staff Moderator
    2025-06-11T04:55:36.08+00:00

    Hi @KKS

    Thank you for reaching out to the Microsoft Q&A Forum. 

    Based on my research, direct username/password authentication is not recommended, especially if MFA is enabled. You can refer to this link for more information > Azure sharepoint multi-factor authentication with python - Stack Overflow 
    You can connect your Microsoft account with Python using the Microsoft Authentication Library (MSAL) for OAuth 2.0. 

    To do this, you need to meet two prerequisites: 

    1. An Azure account with an active subscription. Create a free account if you don't have one. 
    2. Python 3.6+. 

    Then, please follow the instruction in this link to acquire tokens to access Microsoft Graph API, SharePoint, Outlook and other service. Overview of the Microsoft Authentication Library (MSAL) for Python - Microsoft Authentication Library for Python | Microsoft Learn 

    You can also explore the broader Microsoft Authentication Libraries (MSAL) documentation | Microsoft Learn for additional authentication flows and implementation details 
    Please note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    I hope this helps! If you have any other questions, feel free to ask. 


    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 


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.