使用python进行Sharepoint身份验证 [英] Sharepoint authentication with python
问题描述
我正在尝试使用python下载一个Excel文件,该文件托管在 Microsoft Azure平台的共享点中.我尝试通过执行以下操作使用HTTPforhumans的request
检索文件:
I'm trying to use python to download an excel file that is hosted in a sharepoint which is part of the Microsoft Azure platform. I tried to retrieve the file with HTTPforhumans's request
by doing:
r = requests.get(url)
但是我的请求一直被拒绝(r.status_code
返回200
),因为在尝试访问该文件之前,我需要登录到有效帐户.我确实有一个有效的帐户和密码,并且可以通过浏览器访问我的帐户和excel文件.但是我不知道如何处理Azure身份验证过程.显然,这并不像做那么简单:
But my requests keep getting denied (r.status_code
returns 200
) because I need to login to a valid account before trying to access the file. I do have a valid account and password, and I can access to my account and to the excel file via the browser. But I have no idea how to deal wit the Azure authentication procedure. And apparently it is not as easy as just doing:
auth = HTTPBasicAuth('email@somewhere.com', 'pass1234')
r = requests.post(url=url, auth=auth)
我的理解是,要遵循流程,但是当我尝试阅读文档时,它就让我望而却步(我是一名工程师,我没有在这种环境中的经验).
It is my uderstanding that there's a flow to follow, but when I try to read the documentation, it just goes over my head (I'm an engineer and I do not have experience in this kind of environment).
有人可以指导我如何登录和下载文件吗?
Can someone guide me in the process of how to login and download the file?
推荐答案
尝试 O365其余python客户端 库.它支持 SharePoint在线身份验证,并允许下载/上传文件,如下所示:请在此处找到代码:
Try O365 rest python client library.it supports SharePoint Online authentication and allows to download/upload a file as demonstrated below: Please find the code here:
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username,password)
ctx = ClientContext(url, ctx_auth)
response = File.open_binary(context, "/Shared Documents/User Guide.docx")
with open("./User Guide.docx", "wb") as local_file:
local_file.write(response.content)
您可以使用以下命令下载最新版本
You can download the latest version using below command
pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git
有关更多参考,请访问链接
For further reference please visit link
希望有帮助.
这篇关于使用python进行Sharepoint身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!