やあ!
最新の2.2.1バージョンのOffice365を使用してSharePointからファイルをダウンロードするのに問題があります。 ファイルをダウンロードしようとすると、requestsモジュールから「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、
Python 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()
なければならないことに注意してください