excel - 尝试通过 Python 访问共享点以下载文件
问题描述
import os
import tempfile
from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
user_credentials = UserCredential('username', 'password')
ctx = ClientContext('https://work.sharepoint.com').with_credentials(user_credentials)
file_url = '/sites/work/Shared Documents/Beta Testing/Practice.xlsx'
download_path = os.path.join(tempfile.mkdtemp(), os.path.basename(file_url))
with open(download_path, "wb") as local_file:
file = ctx.web.get_file_by_server_relative_path(file_url).download(local_file).execute_query()
print("[Ok] file has been downloaded: {0}".format(download_path))
尝试使用此代码访问然后从共享点下载特定文件(出于明显的原因,所有机密部分都被编辑掉),每当我尝试此操作时,我要么得到 404 Client Error Not Found for url: 要么 400 Client Error :对 url 的错误请求:如果我在 file_url 中的站点/工作之前添加 url 的 ctx 部分。
解决方案
推荐阅读
- arrays - 删除切片中的元素
- sql-server - 为什么会出现错误“您必须声明标量变量@xxx”?
- xamarin - Cosmos DB + 分区键 + 存储过程
- python - 通过 object.fk.id 和 object.fk_id 查找外键的区别
- javascript - 如何使用瓦片坐标谷歌地图填充瓦片内的颜色?
- php - 未收到 POST 请求
- javascript - angularjs:在加载打开到新标签的第二页时,主页的 UI 被阻止
- c++ - c++在char开头插入char
- r - 将字符串拆分为新变量
- kendo-ui - 当我们在 IE 浏览器中单击打开它时,Kendo Dropdown 会关闭