Python-从SharePoint网站下载文件

Python-从SharePoint网站下载文件,python,sharepoint,Python,Sharepoint,我需要下载文件并将其上载到Sharepoint网站。这必须使用python来完成。 我的网站将被进一步的链接 起初我以为我可以使用Request、BeautifulSoup等来完成这项工作,但我根本无法在站点主体上“检查元素” 我尝试过Sharepoint、HttpNtlAuth、office365等库,但没有成功。它总是返回403 我尽我所能尝试谷歌,但还是没有成功。连Youtube都帮不了我 有人能帮我怎么做吗?关于图书馆与文档链接的建议非常感谢 谢谢您是否尝试过,它支持并允许下载/上传文件

我需要下载文件并将其上载到Sharepoint网站。这必须使用python来完成。 我的网站将被进一步的链接 起初我以为我可以使用Request、BeautifulSoup等来完成这项工作,但我根本无法在站点主体上“检查元素”

我尝试过Sharepoint、HttpNtlAuth、office365等库,但没有成功。它总是返回403

我尽我所能尝试谷歌,但还是没有成功。连Youtube都帮不了我

有人能帮我怎么做吗?关于图书馆与文档链接的建议非常感谢

谢谢

您是否尝试过,它支持并允许下载/上传文件,如下所示:

下载文件

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)   
ctx = ClientContext(url, ctx_auth)
response = File.open_binary(ctx, "/Shared Documents/User Guide.docx")
with open("./User Guide.docx", "wb") as local_file:
    local_file.write(response.content)
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)   
ctx = ClientContext(url, ctx_auth)

path = "./User Guide.docx" #local path
with open(path, 'rb') as content_file:
   file_content = content_file.read()
target_url = "/Shared Documents/{0}".format(os.path.basename(path))  # target url of a file 
File.save_binary(ctx, target_url, file_content) # upload a file
上传文件

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)   
ctx = ClientContext(url, ctx_auth)
response = File.open_binary(ctx, "/Shared Documents/User Guide.docx")
with open("./User Guide.docx", "wb") as local_file:
    local_file.write(response.content)
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)   
ctx = ClientContext(url, ctx_auth)

path = "./User Guide.docx" #local path
with open(path, 'rb') as content_file:
   file_content = content_file.read()
target_url = "/Shared Documents/{0}".format(os.path.basename(path))  # target url of a file 
File.save_binary(ctx, target_url, file_content) # upload a file
用法

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)   
ctx = ClientContext(url, ctx_auth)
response = File.open_binary(ctx, "/Shared Documents/User Guide.docx")
with open("./User Guide.docx", "wb") as local_file:
    local_file.write(response.content)
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)   
ctx = ClientContext(url, ctx_auth)

path = "./User Guide.docx" #local path
with open(path, 'rb') as content_file:
   file_content = content_file.read()
target_url = "/Shared Documents/{0}".format(os.path.basename(path))  # target url of a file 
File.save_binary(ctx, target_url, file_content) # upload a file
安装最新版本(从GitHub):


有关更多详细信息,请参阅

是否查看了请求库?由于身份验证错误而引发403错误。您应该检查是否有权访问此网站,以及是否在请求中提供身份验证数据。能否提供指向SharePoint工作网站的链接?也许我们可以从我们所期望的页面结构开始反向工作。我也尝试了请求库。。但不起作用。。。要求将文件上载到后端的sharepoint,以便web用户可以使用该文件。我们有python库sharepoint的文档吗?请告诉我ClientContext、File、context指的是什么。。。要从哪个文件导入哪个特定模块?@DKS,答案已更新,您可以找到完整的示例,我的公司强迫我使用Anaconda与python一起工作。我一直在尝试安装你列出的软件包,但它回来时说“当前频道没有可用的软件包”,我可以用Anaconda进行验证。我每天需要下载一个sharepoint文件,这似乎很有用(直到不起作用::-),但我发现它不允许我编辑答案,因为用户不接受编辑。以下是使其工作的导入:从office365.runtime.auth.authentication\u上下文从office365.sharepoint.client导入AuthenticationContext\u上下文从office365.sharepoint.file导入ClientContext