如何解决通过python脚本上传文件到sharepoint
我编写了以下脚本以将文件上传到共享点文件夹。脚本运行没有任何错误,但文件没有显示在 sharepoint 文件夹中,你能指出我哪里出错了吗?我一直在使用 office-365-REST-python
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
import os
# Set Login Info
def up():
ctx_auth = AuthenticationContext("https://abc.sharepoint.com/sites/bootrom/Shared%20Documents/Forms/AllItems.aspx?originalPath=aHR0cHM6Ly9ueHAxLnNoYXJlcG9pbnQuY29tL") #just an example
ctx_auth.acquire_token_for_user("rkp@abc.com","password")
ctx = ClientContext("https://abc.sharepoint.com/sites/bootrom/Shared%20Documents/Forms/AllItems.aspx?originalPath=aHR0cHM6Ly9ueHAxLnNoYXJlcG9pbnQuY29tL",ctx_auth)
path = "static\\Beast_S32k344\\BEAST\\Projects\\TestCases\\TestCaseDatabase\\Sprint3_Test_Report.xlsx" #local path
with open(path,'rb') as content_file:
file_content = content_file.read()
target_url = "/Shared%20Documents/Forms/AllItems.aspx?originalPath=aHR0cHM6Ly9ueHAxLnNoYXJlcG9pbnQuY29tL".format(os.path.basename(path)) # target url of a file
File.save_binary(ctx,target_url,file_content) # upload a file
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。