使用 SharePlum for Sharepoint 下载文件

File Download Using SharePlum for Sharepoint

我正在使用 SharePlum 来处理 Sharepoint files/folder 操作。我可以使用 Shareplum 创建文件夹和上传文件。但是我无法下载文件。代码运行没有任何问题。我不确定文件的下载位置。

def download():
    auth_cookie = Office365(base_path, username=username, password=password).GetCookies()
    full_path = urllib.parse.urljoin(urllib.parse.urljoin(base_path, "sites/"), site_name)
    logging.info("URL: %s", full_path)
    site = Site(full_path, version=Version.v2016, authcookie=auth_cookie)
    folder = site.Folder(folder_name)
    logging.info("folder name: %s", folder_name)
    folder.get_file('file.txt')
    folder.check_out(download_file)
    logging.info("Downloaded")

示例演示:

from shareplum import Site
from shareplum import Office365
from shareplum.site import Version

authcookie = Office365('https://xxx.sharepoint.com', username='user@xxx.onmicrosoft.com', password='password').GetCookies()
site = Site('https://xxx.sharepoint.com/sites/lee/', version=Version.v2016,authcookie=authcookie)
folder = site.Folder('MyDoc2')

file=folder.get_file('testdata.xlsx')
with open("testdata.xlsx", "wb") as fh:
    fh.write(file)
print('---')