Hai!
Saya mengalami masalah saat mengunduh file dari SharePoint menggunakan Office365 versi 2.2.1 terbaru. Ketika saya mencoba mengunduh file, Kesalahan "MissingSchema" dari modul permintaan muncul. Saya tidak tahu apa yang terjadi, jika saya kembali ke versi 2.1.5 kodenya berjalan dengan baik. Terima kasih banyak dan saya menghargai kerja keras dalam modul ini; sangat berguna!
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)
Kesalahan:
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?
Menggunakan MacOS,
Office365 2.2.1,
Python 3.8.3,
permintaan 2.2.4
Ada bug dalam versi 2.2.1 yang perlu Anda gunakan yang terbaru dari git atau perbaiki secara manual di instalasi Anda di sini https://github.com/vgrem/Office365-REST-Python-Client/blob/master/office365/sharepoint /files/file.py#L275
Perhatikan bahwa di versi Anda ctx.service_root_url
adalah properti tetapi harus berupa metode ctx.service_root_url()
Terima kasih @efremovd dan @etiennecelery untuk menangkap dan menunjukkannya, memang itu adalah bug dan ditemukan di versi 2.2.1
karena refactoring properti service_root_url
ke metode.
Seperti yang telah disebutkan, versi _latest_ yang tersedia dari GitHub menyelesaikan masalah ini:
pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git
Atau, file dapat diunduh seperti yang ditunjukkan di bawah ini:
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()
Terima kasih!! Kerja bagus
Menutup yang ini sejak telah diselesaikan dan versi 2.2.2
telah dirilis.
Komentar yang paling membantu
Ada bug dalam versi 2.2.1 yang perlu Anda gunakan yang terbaru dari git atau perbaiki secara manual di instalasi Anda di sini https://github.com/vgrem/Office365-REST-Python-Client/blob/master/office365/sharepoint /files/file.py#L275
Perhatikan bahwa di versi Anda
ctx.service_root_url
adalah properti tetapi harus berupa metodectx.service_root_url()