from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.http.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
ctx_auth = AuthenticationContext("https://infarmahonduras.sharepoint.com/sites/ContabilidadInfarma")
ctx_auth.acquire_token_for_user("xxxxxxxx","xxxxxxx")
ctx = ClientContext("https://infarmahonduras.sharepoint.com/sites/ContabilidadInfarma", ctx_auth)
relative_url= "/sites/ContabilidadInfarma/Documents/Mercadeo202005.xlsx"
filename = 'Mercadeo202005.xlsx'
with open(filename, 'wb') as output_file:
response = File.open_binary(ctx, relative_url)
output_file.write(response.content)
print(response.content)**
#我的问题是,它下载了文件,但不超过1KB,将扩展名更改为XLS时,原始文件大小为189KB。写入以下错误
{“error”:{“code”:“-2130575338,Microsoft.SharePoint.SPException”,“message”:{“lang”:“es”,“value”:“El archivo/sites/ContabilidadInfarma/Documents/Mercadeo202005.xlsx不存在”。}}}
@FernandoGFMC
我在我的SPO环境中测试了你的代码,在这里它运行良好。从错误消息来看,文件的相对url似乎不正确
如果文件位于默认库中,则ServerRelativeUrl应为:
“文档”是列表名,而共享文档是根文件夹。事实上,如果我设置了错误的URL,我会产生错误:
溴
相关问题 更多 >
编程相关推荐