Office365-REST-Python-Client
Office365-REST-Python-Client copied to clipboard
download file from sharepoint return 400 error
I got: 'Attempted to perform an unauthorized operation.', "403 Client Error: Forbidden for url:.... when i tried to download not from my own sharepoint but still public and accessible from browser (its works normal when i download from my own)
import os
import tempfile
from office365.sharepoint.client_context import ClientContext
from tests import test_client_credentials, test_team_site_url
#client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
user_credentials = UserCredential('{user}','{password}')
ctx = ClientContext(site_url).with_credentials(user_credentials)
client = ClientContext(team_site_url).with_credentials(user_credentials)
sharing_link_url = "https://mediadev8.sharepoint.com/:x:/s/team/EcEbi_M2xQJLng_bvQjPtgoB1rB6BFvMVFixnf4wOxfE5w?e=bzNjb6"
download_path = os.path.join(tempfile.mkdtemp(), "Report.csv")
with open(download_path, "wb") as local_file:
file = (
client.web.get_file_by_guest_url(sharing_link_url)
.download(local_file)
.execute_query()
)
print("[Ok] file has been downloaded into: {0}".format(download_path))
Whats the issue?