Avoid shared lock when using Office365-REST-Python-Client-2.3.16

578 views Asked by At

I am trying to update a file on sharepoint using Office365-REST-Python-Client-2.3.16. But if I open this file in a browser, I will always get:

office365.runtime.client_request_exception.ClientRequestException: ('-2147018894, Microsoft.SharePoint.SPFileLockException', 'The file https://aaa.sharepoint.com/sites/bbb/Shared Documents/ccc.xlsx is locked for shared use by [email protected] [membership].', "423 Client Error: Locked for url: https://aaa.sharepoint.com/sites/bbb/_api/Web/getFolderByServerRelativeUrl('Shared%20Documents')/Files/add(overwrite=true,url='ccc.xlsx')")

The 'bypass-shared-lock' works when I try to delete a file, but doesn't work for uploading a file.

def custom_header(request):
    request.headers['Prefer'] = 'bypass-shared-lock'

ctx.before_execute(custom_header)
ctx.web.get_folder_by_server_relative_url(dir).upload_file(name, content).execute_query()

Is it possible to ignore the lock and force update?

1

There are 1 answers

3
Will Drotar On

The same issue exists with the requests library. For now this looks an issue within Microsoft Graph.

In the Graph portal using bypass-shared-lock in the Request headers, it's only able to delete but NOT update anything. Looking online there doesn't seem to be a workaround yet.