Hi @Asnal Rizvi,
You could try to set Shared Documents/filename.docx
as file_path. Please refer to following code
"""
Demonstrates how to download a file from SharePoint site
"""
import os
import tempfile
from office365.sharepoint.client_context import ClientContext
from tests import test_client_credentials, test_team_site_url
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
file_url = "Shared Documents/big_buck_bunny.mp4"
# file_url = "Shared Documents/!2022/Financial Sample.xlsx"
download_path = os.path.join(tempfile.mkdtemp(), os.path.basename(file_url))
with open(download_path, "wb") as local_file:
file = (
ctx.web.get_file_by_server_relative_url(file_url)
.download(local_file)
.execute_query()
)
print("[Ok] file has been downloaded into: {0}".format(download_path))
---If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.