Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch update items in a list returns 400 error #349

Closed
AndersFreund opened this issue May 4, 2021 · 1 comment
Closed

Batch update items in a list returns 400 error #349

AndersFreund opened this issue May 4, 2021 · 1 comment

Comments

@AndersFreund
Copy link

I am using the script from the examples, adding my own site.
https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/lists_and_items/update_items_batch.py

I can retrieve the list, and I can update items individualy, but the batch update fails.

Traceback (most recent call last):
  File "C:/projects/sharepoint API/Sharepoint API test.py", line 25, in <module>
    ctx.execute_batch()
  File "c:\repos\dev\office365-rest-python-client\office365\sharepoint\client_context.py", line 108, in execute_batch
    batch_request.execute_query()
  File "c:\repos\dev\office365-rest-python-client\office365\runtime\client_request.py", line 83, in execute_query
    self.process_response(response)
  File "c:\repos\dev\office365-rest-python-client\office365\runtime\odata\odata_batch_request.py", line 33, in process_response
    for response_info in self._read_response(response):
  File "c:\repos\dev\office365-rest-python-client\office365\runtime\odata\odata_batch_request.py", line 55, in _read_response
    yield self._deserialize_response(raw_response)
  File "c:\repos\dev\office365-rest-python-client\office365\runtime\odata\odata_batch_request.py", line 99, in _deserialize_response
    raise ValueError(response)
ValueError: HTTP/1.1 400 Bad Request
CONTENT-TYPE: application/xml;charset=utf-8

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-1, Microsoft.SharePoint.Client.InvalidClientQueryException</m:code><m:message xml:lang="en-US">Invalid request.</m:message></m:error>
@vgrem
Copy link
Owner

vgrem commented Jul 8, 2021

Greetings,

the error most likely occurs when batch request is large enough and exceeds a certain boundary, according to List and library limits :

image

In the latest version (2.3.5 at the moment) the support for batch requests has been improved in terms of introducing items_per_bulk parameter:

ClientContext.execute_batch(items_per_bulk=100)

which allows to control the max amount of operations per batch request (100 by default)
In case batch request exceeds this value, it is getting splitted into a smaller chunks before submitting to the server.

Thank you for catching it and reporting,
Vadim

@vgrem vgrem closed this as completed Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants