You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importconcurrent.futuresfromoffice365.sharepoint.client_contextimportClientContextfromoffice365.sharepoint.files.move_operationsimportMoveOperationsctx: ClientContext=ClientContext(base_url='https://example.sharepoint.com/sites/tenant').with_user_credentials(
username='test_user', password='test_password')
defmain(source_filename):
"""Moves a file from source folder to destination folder. Args: source_filename: Name of the file. """ctx.web.get_file_by_server_relative_path(path=f'Shared Documents/{source_filename}').move_to_using_path(
destination='Shared Documents/destination_folder', flag=MoveOperations.overwrite).execute_query()
>>>withconcurrent.futures.ThreadPoolExecutor() asexecutor:
... executor.map(main, ['one.csv', 'two.csv', 'three.csv'])
office365.runtime.client_request_exception.ClientRequestException: ('-2147024809, System.ArgumentException', 'Server relative urls must start with SPWeb.ServerRelativeUrl', "400 Client Error: Bad Request for url: https://example.sharepoint.com/sites/tenant/_api/Web/getFileByServerRelativePath(DecodedUrl='%2Fsites%2Ftenant%2FShared%20Documents%2Fone.csv')/MoveToUsingPath(DecodedUrl='%2Fone.csv',moveOperations=1)")
Use copy.deepcopy to prevent the statefulness of the object from being overwritten by other threads.
defmain(source_filename):
"""Moves a file from source folder to destination folder. Args: source_filename: Name of the file. """importcopycopy.deepcopy(ctx).web.get_file_by_server_relative_path(path=f'Shared Documents/{source_filename}').move_to_using_path(
destination='Shared Documents/destination_folder', flag=MoveOperations.overwrite).execute_query()
The text was updated successfully, but these errors were encountered:
Sometimes you have to move a bunch of files together to another folder. If you use move_to_using_path concurrently using ThreadPoolExecutor, ClientRequestException is raised.
How to reproduce
It will work fine if there is only one thread.
Workaround
Use
copy.deepcopy
to prevent the statefulness of the object from being overwritten by other threads.The text was updated successfully, but these errors were encountered: