【发布时间】:2021-05-07 04:49:12
【问题描述】:
我正在尝试读取存储在 Sharepoint 中的 excel 文件。但我做不到。我已经参考了大多数现有文章,但这并没有解决我的问题。
我引用的代码来自:How to read SharePoint Online (Office365) Excel files in Python with Work or School Account?
Read xlsx stored on sharepoint location with openpyxl in python?
但没有运气。
import io
import json
import pandas as pd
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.auth.user_credential import UserCredential
from office365.runtime.http.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
from io import BytesIO
username = '##########################'
password = '##########################'
site_url = "#######################################################"
ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
request = RequestOptions("{0}/_api/web/".format(site_url))
response = ctx.execute_request_direct(request)
json_data = json.loads(response.content)
【问题讨论】:
-
我前一阵子尝试过这样做,结果只是在本地将sharepoint文件夹与我的机器“同步”,这样更容易读写。
标签: python sharepoint