你好!
我在使用最新的 2.2.1 版 Office365 从 SharePoint 下载文件时遇到问题。 当我尝试下载文件时,会出现请求模块中的“MissingSchema”错误。 我不知道发生了什么,如果我回到 2.1.5 版,代码运行良好。 非常感谢,我感谢这个模块的辛勤工作; 超级好用!
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
def auth(username, password):
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
ctx = ClientContext(url, ctx_auth)
return ctx
ctx = auth(username, password)
response = File.open_binary(ctx, relative_url)
错误:
MissingSchema: Invalid URL "<bound method ClientContext.service_root_url of <office365.sharepoint.client_context.ClientContext object at 0x7fb4e44c3d90>>web/getfilebyserverrelativeurl('MYRELATIVEURL')/\\$value": No schema supplied. Perhaps you meant http://<bound method ClientContext.service_root_url of <office365.sharepoint.client_context.ClientContext object at 0x7fb4e44c3d90>>web/getfilebyserverrelativeurl('MYRELATIVEURL')/\$value?
使用 MacOS,
Office365 2.2.1,
蟒蛇 3.8.3,
请求 2.2.4
2.2.1 版本中有一个错误,您需要使用来自 git 的最新版本,或者在此处的安装中手动修复它https://github.com/vgrem/Office365-REST-Python-Client/blob/master/office365/sharepoint /files/file.py#L275
请注意,在您的版本中ctx.service_root_url
是一个属性,但应该是一个方法ctx.service_root_url()
感谢@efremovd和@etiennecelery捕获并查明它,确实它是一个错误,并且由于将service_root_url
属性重构为方法而在2.2.1
版本中遇到。
如前所述,GitHub 提供的 _latest_ 版本解决了这个问题:
pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git
或者,可以按如下所示下载该文件:
file_url = '{server-relative-path-to-download}'
with open(download_path, "wb") as local_file:
file = ctx.web.get_file_by_server_relative_url(file_url).download(local_file).execute_query()
谢谢!! 做得好
自此关闭此问题已解决,并且已发布2.2.2
版本。
最有用的评论
2.2.1 版本中有一个错误,您需要使用来自 git 的最新版本,或者在此处的安装中手动修复它https://github.com/vgrem/Office365-REST-Python-Client/blob/master/office365/sharepoint /files/file.py#L275
请注意,在您的版本中
ctx.service_root_url
是一个属性,但应该是一个方法ctx.service_root_url()