如何从组织sharepoint下载文件?

2024-09-23 22:17:50 发布

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

我正在尝试使用python脚本访问组织sharepoint,但是我做不到。我已经尝试了所有我们可以使用的python库。可能我没有创建正确的请求负载,但我不知道如何为特定组织创建sharepoint请求。 谢谢

我已经试过了,请求.HTTPBasicAuth,office365,sharepoint和sharepy python库。你知道吗

import requests

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.utilities.request_options import RequestOptions

url = "https://organization.sharepoint.com/sites/BIRE/Shared%20Documents/Forms/AllItems.aspx?RootFolder=/sites/BIRE/Shared Documents/folder"

username = "user_name"
password = "Password"

ctx_auth = AuthenticationContext(url)
token = ctx_auth.acquire_token_for_user(username, password)
print( token)
options = RequestOptions(url)
ctx_auth.authenticate_request(options)

req = requests.get(url, headers=options.headers, verify=False, allow_redirects=True)

我想点击URL并下载具有给定名称的文件。你知道吗


Tags: fromimporttokenauthurlrequestrequestssites
1条回答
网友
1楼 · 发布于 2024-09-23 22:17:50

如果你提供一些你得到的错误信息,这会很有帮助。但是从代码的角度来看,您只是缺少了将输出保存到文件的结尾部分。你知道吗

output = open('filename.xlsx', 'wb')
output.write(req.content)  
output.close()`

相关问题 更多 >