【发布时间】:2020-04-08 13:29:49
【问题描述】:
我正在尝试将一些文件(多个文件和文件夹)上传到共享点,当我运行脚本时我没有任何错误,但我无法在共享点中查看我的文件。
import requests
from shareplum import Office365
# get data from configuration
username = 'last.surname@tenant.com'
password = 'mypassword'
site_name = 'BI_odair'
base_path = 'https://tenant.sharepoint.com'
doc_library = 'data'
file_name = "links.txt"
# Obtain auth cookie
authcookie = Office365(base_path, username=username,
password=password).GetCookies()
session = requests.Session()
session.cookies = authcookie
session.headers.update({'user-agent': 'python_bite/v1'})
session.headers.update({'accept': 'application/json;odata=verbose'})
# perform the actual upload
with open(file_name, 'rb') as file_input:
try:
response = session.post(
url=base_path + "/sites/" + site_name +
"/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/" +
doc_library+"')/Files/add(url='"
+ file_name + "',overwrite=true)",
data=file_input)
except Exception as err:
print("Some error occurred: " + str(err))
我的分享点网址:https://tenant.sharepoint.com/sites/BI_odair/Documents%20partages/Forms/AllItems.aspx?viewid=4e7fdfb9%2De84a%2D42cd%2Db537%2D0d2837ca92cc 已经有一个名为 Data 的文件夹,但我想将我的文件上传到根文件夹“/Documents%20partages”
我已经将此添加到我的代码中:https://stackoverflow.com/a/59083429/6754555
提前致谢。
【问题讨论】:
标签: python-3.x file sharepoint file-upload