[英]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.我正在尝试使用库 office365 将文件从 SharePoint 中的一个文件夹移动到另一个文件夹。
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谁能帮我解决这个错误
Maybe you can try this:也许你可以试试这个:
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)
source_file = ctx.web.get_file_by_server_relative_url(old_url)
source_file.moveto(new_relative_url=new_url, flag=1)
ctx.execute_query()
Thanks.谢谢。
Reference: https://github.com/vgrem/Office365-REST-Python-Client/issues/157参考: https://github.com/vgrem/Office365-REST-Python-Client/issues/157
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.