Skip to content

400: JSON is malformed: invalid character when trying to send binary data #2762

Discussion options

You must be logged in to vote

Also I do not want to use multi-part requests for infra reasons).

But you are. Passing a dict to data will cause it to be form encoded.

From the requests docs:

data – the body to attach to the request. If a dictionary or list of tuples [(key, value)] is provided, form-encoding will take place.

https://requests.readthedocs.io/en/latest/api/#requests.Request

The error you are seeing is because you are telling Litestar to decode form encoded data as JSON.

You need to either send your data as JSON (e.g. by encoding it as a string before passing it to the data parameter, or passing your dictionary to the json parameter instead), or by setting the appropriate content-type in your handler so…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JacobCoffee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Question This is a question and further information is requested
2 participants
Converted from issue

This discussion was converted from issue #2761 on November 26, 2023 12:18.