Reputation: 55
Good morning
I have a Microsoft Teams account. On this account I need to download and update file, that are saved in SharePoint.
I can connect to the SharePoint and to download and upload a file.
I would like to implement a script that do it authomatically.
I tried to do it with Python and with the library Office365-REST-Python-Client.
I used the code in the documentation
[https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/files/download_file.py][1]
The only difference is that I used to connect to SharePoint the user credential
ctx = ClientContext(url).with_user_credentials(username, password)
I can connect to SharePoint without errors, but when I tried to download the file I have the following error
Traceback (most recent call last):
File "download.py", line 25, in <module>
file = ctx.web.get_file_by_server_relative_url(file_da_scaricare_url).download(local_file).execute_query()
File "C:\Users\<user>\AppData\Roaming\Python\Python39\site-packages\office365\runtime\client_object.py", line 31, in execute_query
self.context.execute_query()
File "C:\Users\<user>\AppData\Roaming\Python\Python39\site-packages\office365\runtime\client_runtime_context.py", line 133, in execute_query
self.pending_request().execute_query()
File "C:\Users\<user>\AppData\Roaming\Python\Python39\site-packages\office365\runtime\client_request.py", line 86, in execute_query
raise ClientRequestException(*e.args, response=e.response)
office365.runtime.client_request_exception.ClientRequestException: ('-2130575338, Microsoft.SharePoint.SPException', 'Il file <path> non esiste.', "404 Client Error: Not Found for url: https://<url>/_api/Web/getFileByServerRelativeUrl('<path>')?$select=ServerRelativeUrl")
The path is correct: if I go to Chrome and I paste the url I can download the file without problem.
Have you got any ideas how to solve or try to debug the problem?
Thanks
Regards
Upvotes: 1
Views: 4886
Reputation: 55
Good morning.
The problem was in the url of my sharepoint passed to
ctx = ClientContext(url).with_user_credentials(username, password)
In my case
WRONG URL => https://<company_name>.sharepoint.com
RIGHT URL => https://<company_name>.sharepoint.com/sites/mySiteName
Upvotes: 3