1

I am trying to upload a CSV of a Pandas DataFrame generated by a Python script to Microsoft SharePoint / OneDrive.

I cannot figure out how to get past the following error when I try to connect to upload a file:

import pandas as pd

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext


df = pd.DataFrame()

site_url = "https://{tenant id: str = ########-####-####-####-############ ???}.sharepoint.com/sites/{site name: str = 'tktktk' ???}"
username = "{user}@{site name}.com"
password = "{tktktk}"

auth_ctx = AuthenticationContext(site_url)
auth_ctx.acquire_token_for_user(username, password)
ctx = ClientContext(site_url, auth_ctx)

web = ctx.web
ctx.load(web)

try:
    ctx.execute_query()
    print(f"Connection to SharePoint site '{web.properties['Title']}' successful!")
except Exception as e:
    print(f"Error connecting to SharePoint: {e}")

Output:

ValueError: Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf

2
  • 1
    This question is similar to: How to upload a file to sharepoint site using python script. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Apr 7 at 19:15
  • @June7 That question doesn't have any code and is a 'how to' question, using Python 2. This is a debugging question about specific code that appears to be Python 3. Not to mention the methods for authenticating to SharePoint have changed drastically (and multiple times) since 2014. Commented Apr 8 at 17:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.