如何使用Python从Sharepoint文档中获取内容并下载文件

2024-04-27 05:19:04 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我正在制作一个程序,需要从sharepoint下载文件,但我无法获得sharepoint文档的内容。我使用sharepy模块遵循了这个tuto,它可以很好地进行身份验证,但不能获得文档的内容。你知道吗

这是我的sharepoint(带有几个测试文件):

enter image description here

我尝试了不同的方法来满足Microsoft documentation

以下是从sharepoint文档获取内容的代码:

def contentSharepoint():
    # (1) Authenticate
    s = sharepy.connect("kinesiprevention.sharepoint.com", username='******', password='******')

    # (2) Get file information
    r = s.get("https://kinesiprevention.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Shared Documents')/Files")
    print('r is :'+str(r))
    data = r.json()
    print('data :' + str(data))
    file = open("sharepoint.json", "w")
    file.write(json.dumps(data, indent=4))
    print("json file has been generated")

我有一个回应,但没有内容:

enter image description here


Tags: 模块文件文档程序comjson内容data