why does this sample code from office365.sharepoint repo fails?

69 views Asked by At

Using Python 3.10 and trying to learn and use Office365-REST-Python-Client to manipulate SharePoint files.

I need to be able to move files around and I came across the following code on their file examples:

their source code

the actual code:

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.move_operations import MoveOperations
from tests import test_team_site_url, test_user_credentials

ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)

file_from = ctx.web.get_file_by_server_relative_path(
    "Shared Documents/Financial Sample.xlsx"
)
folder_to = "Shared Documents"

file_to = file_from.move_to_using_path(
    folder_to, MoveOperations.overwrite
).execute_query()
print("'{0}' moved into '{1}'".format(file_from, file_to))

when I run the above code, the error I get is:

File does not have a move_to_using_path function defined.

How can the above be corrected?

1

There are 1 answers

0
iambdot On

I am using version Office365-REST-Python-Client==2.5.2 and this works for me. make sure you have updated version

file_from = ctx.web.get_file_by_server_relative_path(sp_file_path)
new_file_path = file_from.move_to_using_path(
    move_to_path, MoveOperations.overwrite
).execute_query()
logger.info(f"'{file_from}' moved into '{new_file_path}'")