Error when updating the list item
I want to change the Status value of the document library item after I download the file. I have following code which works fine for downloading and renaming it. But when I update the status, I get error. Codes below with error.
doc_lib = ctx.web.lists.get_by_title(list_title)
items = doc_lib.items.select(["FileSystemObjectType","Status"]).expand(["File"]).filter('startswith(Status,%27new%27)').get().execute_query()
for item in items: # type: ListItem
filename, file_extension = os.path.splitext(item.file.serverRelativeUrl)
if file_extension.lower() == ".csv":
download_path = os.path.join('.', os.path.basename(item.file.serverRelativeUrl))
with open(download_path, "wb") as local_file:
file = ctx.web.get_file_by_server_relative_path(item.file.serverRelativeUrl).download(local_file).execute_query()
file.moveto(item.file.serverRelativeUrl+"_downloaded",1).execute_query()
item.set_property('Status','Downloaded').update().execute_query()
And I get following error:
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\office365\runtime\client_request.py", line 94, in execute_query
response.raise_for_status()
File "C:\Python38\lib\site-packages\requests\models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://<TenantName>.sharepoint.com/sites/<SiteName>/IM_DDC/IM_FDL/_api/ParentList?$select=ListItemEntityTypeFullName
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "connect_sharepoint_IMDDC_aq.py", line 40, in <module>
item.set_property('Status','Downloaded').update().execute_query()
File "C:\Python38\lib\site-packages\office365\runtime\client_object.py", line 41, in execute_query
self.context.execute_query()
File "C:\Python38\lib\site-packages\office365\runtime\client_runtime_context.py", line 132, in execute_query
self.pending_request().execute_query()
File "C:\Python38\lib\site-packages\office365\runtime\client_request.py", line 98, in execute_query
raise ClientRequestException(*e.args, response=e.response)
office365.runtime.client_request_exception.ClientRequestException: ('-1, Microsoft.SharePoint.Client.ResourceNotFoundException', 'Cannot find resource for the request ParentList.', '404 Client Error: Not Found for url: https://<TenantName>.sharepoint.com/sites/<SiteName>/IM_DDC/IM_FDL/_api/ParentList?$select=ListItemEntityTypeFullName')
Let me know what am I doing wrong here.
nojha
Are you uploading a file with a very long filename by any chance? I'm hitting a similar issue, but it's only for long filenames.
No, I just want to change the status property/attribute. No file upload, I am downloading the file. The filename in the document library is less than 50 characters.
Ah, ok. Must be a different issue then. Thx.
I was having this error message when trying to update listitems as well. I found two solutions that fixed it for me
- adding "id" to my select list (the better solution)
- removing the select entirely
I'm not sure why this fixes the issue. I spent some hours in the debugger working to understand how queries are constructed but I couldn't get to the bottom of it in a reasonable amount of time. @vgrem I would appreciate your insight here to help our understanding.
One final note for my particular case is that my list is a library not just a vanilla list. Based on OPs variable name, doc_lib, I suspect they are may be using a library as well. Maybe that's interesting to you vgrem, maybe not.
Anyway, I hope this helps some of you. Cheers!
Turns out it was a library bug, namely the list item update request was not properly constructed.
Thank you for reporting it!
It has been addresed in a new 2.5.3 version
Similar issue: #764