Hello I have problems with the connection I make from python to share point of one drive and it happens that I want to access an excel file but I have this error.
There was an error retrieving the XML response token: AADSTS50076: Due to a configuration change made by your administrator, or because you have moved to a new location, you must use multi-factor authentication to access ‘
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
import io
import pandas as pd
# File URL in SharePoint and credentials
url="https://companymy.sharepoint.com/personal/yo_compnay/Documents/prueba/document.xlsx"
username="[email protected]"
password = 'xxxx'
# Create authentication context
ctx_auth = AuthenticationContext(url)
# Attempt to acquire token with user authentication (username and password)
if ctx_auth.acquire_token_for_user(username, password):
# If authentication succeeds, create client context.
ctx = ClientContext(url, ctx_auth).
# Get the binary file
response = File.open_binary(ctx, url)
# Store data in a BytesIO stream object
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0) # Set file object at startup
# Read the Excel file and each sheet in a pandas dataframe
df = pd.read_excel(bytes_file_obj, sheet_name=None).
else:
print("Error: failed multifactor authentication.")