我正在尝试使用 Python 脚本从 SharePoint 存储库下载 Excel 文件。我正在使用 Office365-Rest-Python-Client,如示例中所定义https://github.com/vgrem/Office365-REST-Python-Client https://github.com/vgrem/Office365-REST-Python-Client我可以访问我需要的所有文件/目录。当我想下载任何文件时就会出现问题。我尝试了几种方法,但没有一个有效:wget.download("https://shprepos.com/path/file.xlsx", local_path, bar=None)
但我收到“403 FORBIDDEN”错误。我也尝试过请求:
req = requests.get(ruta, auth=requests.auth.HTTPBasicAuth(username, password), headers=headers)
with open(local_file, 'wb') as file:
file.write(req.content)
通过这段代码,我得到的是网页,而不是 Excel 文件,我不明白为什么,因为如果我访问 url ”https://shprepos.com/path/file.xlsx https://shprepos.com/path/file.xlsx”,通过正确的身份验证,我下载了该文件。
您知道使用身份验证使用 wget 下载该文件的方法吗?或者我在 requests.get 中做错了什么?
我需要一种获取该文件的方法,使用我在脚本开头所做的先前身份验证:
ctx_auth = AuthenticationContext(shp_url)
token = ctx_auth.acquire_token_for_user(username, password)
你知道这样做的方法吗?也许python客户端有一个下载文件的方法,但我找不到它!
非常感谢! :)
Regards