'Move file from one folder to another in sharepoint using Python

I am trying to move the file from one folder to another in SharePoint using library office365.

below is the code that I have written -

from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.client_request_exception import ClientRequestException
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.files.file import File

ctx_auth = AuthenticationContext(url_shrpt)
if ctx_auth.acquire_token_for_user(username_shrpt,password_shrpt):
  ctx = ClientContext(url_shrpt, ctx_auth)
  file = ctx.web.get_file_by_server_relative_url(old_url)
  ctx.load(file)
  ctx.execute_query()
  File.moveto(ctx, new_relative_url=new_url, flag=1)

I am getting the error -

"'ClientContext' object has no attribute 'context'"
AttributeError                            Traceback (most recent call last)
<command-527297> in <module>
      6   ctx.load(file)
      7   ctx.execute_query()
----> 8   File.copyto(ctx, new_relative_url=new_url, overwrite=True)

/databricks/python/lib/python3.8/site-packages/office365/sharepoint/files/file.py in copyto(self, new_relative_url, overwrite)
    124         :type overwrite: bool
    125         """
--> 126         qry = ServiceOperationQuery(self,
    127                                     "CopyTo",
    128                                     {

/databricks/python/lib/python3.8/site-packages/office365/runtime/queries/service_operation_query.py in __init__(self, binding_type, method_name, method_params, parameter_type, parameter_name, return_type, is_static)
     16         :type method_name: str or None
     17         """
---> 18         super(ServiceOperationQuery, self).__init__(binding_type.context,
     19                                                     binding_type,
     20                                                     parameter_type,

AttributeError: 'ClientContext' object has no attribute 'context'

Can anyone help me with this error



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source