From d136856e1a3660324c2645cec4b2977bb128dd87 Mon Sep 17 00:00:00 2001 From: J01024 Date: Thu, 5 Dec 2024 16:17:35 +0000 Subject: [PATCH] Add urllib parse quote encoding to the URL before executing save or open binary. --- office365/sharepoint/files/file.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/office365/sharepoint/files/file.py b/office365/sharepoint/files/file.py index 27787e20..5ae7314e 100644 --- a/office365/sharepoint/files/file.py +++ b/office365/sharepoint/files/file.py @@ -1,5 +1,6 @@ import datetime from typing import TYPE_CHECKING, AnyStr +from urllib.parse import quote import requests @@ -607,8 +608,11 @@ def save_binary(context, server_relative_url, content): :type server_relative_url: str :type content: str """ - url = r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format( - context.service_root_url(), server_relative_url + url = quote( + r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format( + context.service_root_url(), server_relative_url + ), + safe=":/", ) request = RequestOptions(url) request.method = HttpMethod.Post @@ -626,8 +630,11 @@ def open_binary(context, server_relative_url): :type server_relative_url: str :return Response """ - url = r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format( - context.service_root_url(), server_relative_url + url = quote( + r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format( + context.service_root_url(), server_relative_url + ), + safe=":/", ) request = RequestOptions(url) request.method = HttpMethod.Get