vgrem / Office365-REST-Python-Client

Microsoft 365 & Microsoft Graph Library for Python
MIT License
1.29k stars 332 forks source link

Moving files between Sharepoint folders cause issues only sometimes #209

Open surajram1 opened 4 years ago

surajram1 commented 4 years ago

As I attempt to move files from one folder to a sub-folder - similar to this example below, I find that this works for certain excel files but not for some others in the same folder. I can't seem to find any pattern in file names or size for this.

ctx = ClientContext(site_url, ctx_auth)
# get a source file located in library 'Shared Documents'
source_file = ctx.web.get_file_by_server_relative_url("/teams/Team123/Shared Documents/Guide.docx")
# move a file into sub folder called 'Archive'
source_file.moveto("/teams/Team123/Shared Documents/Archive/Guide.docx", 1)
# execute a query
ctx.execute_query()

The error I receive is ClientRequestException: (None, None, "401 Client Error: Unauthorized for url:..... which is weird as I authenticated through client ID and Secret and all the files are in the same folder but only some files have this issue.

I find when I was using Sharepy, these files are moved without issue when I call the files by 'GetFileById' whereas in office365 library, I am taking file by relative url (get_file_by_server_relative_url). I didn't find a way to take file by ID here. Can someone help with this

erfannariman commented 3 years ago

Were you able to solve this? I get the same error, but for any file.

thomasfrederikhoeck commented 3 years ago

I think this is related to the error in #319