我试图使用库SharePoint将文件从一个文件夹移动到另一个文件夹。
下面是我写的代码-
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)
我搞错了-
"'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'
有人能帮我解决这个错误吗?
发布于 2022-08-30 08:26:22
也许你可以试试这个:
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()
谢谢。
参考资料:https://github.com/vgrem/Office365-REST-Python-Client/issues/157
https://stackoverflow.com/questions/70835375
复制相似问题