如何在 Sharepoint 中读取 Excel 工作表?

问题描述 投票:0回答:1

目前我正在开发一个项目,该项目涉及获取存储在 Sharepoint 中的 Excel 工作表,将其作为 Pandas 中的数据框读取,然后对其执行一些与此问题无关的其他操作。我的问题源于这样一个事实:我的公司使用两因素身份验证来登录我们的帐户,而我不太清楚如何绕过它。

另外,因为它可能相关:我正在 jupyter 笔记本中工作。

我的代码目前如下所示:

import io
import pandas as pd
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File 

url = 'https://COMPANY.sharepoint.com/:x:/s/COMPANYNAME/XXXXXXXXXXXXXXXXXXXXXXXX'
username = "USER"
password = "PASSWORD"

ctx_auth = AuthenticationContext(url)

if ctx_auth.acquire_token_for_user(username, password):
  ctx = ClientContext(url, ctx_auth)
  web = ctx.web
  ctx.load(web)
  ctx.execute_query()

response = File.open_binary(ctx, url)

bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0) #set file object to start


df = pd.read_excel(bytes_file_obj, sheetname = None)

我收到回复:

ValueError: Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf
来自第 18 行 (
ctx.execute_query()
)。

我有点不知道该尝试什么,我读过几篇文章,但没有一篇有任何重大帮助,所以非常感谢这里的任何建议!

python sharepoint jupyter-notebook office365
1个回答
0
投票

您找到解决这个问题的方法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.