400: JSON is malformed: invalid character when trying to send binary data #2762
-
DescriptionHello, I have a client that sends a pytorch model (after converting it to base64 string), for which I want my litestar server to read it and use it afterwards. My client code:
My server code:
However, my litestar server is throwing the following error:
I tried using dict[str, str] instead of creating a dataclass but it did not help. What should I do for my scenario? Note that sending a pytorch model is just an example; I might send a tensor or anything else that is not a simple class. Also I do not want to use multi-part requests for infra reasons). URL to code causing the issueNo response MCVENo response Steps to reproduceNo response ScreenshotsNo response LogsNo response Litestar Version2 (latest) Platform
Note While we are open for sponsoring on GitHub Sponsors and Check out all issues funded or available for funding on our Polar.sh Litestar dashboard
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
But you are. Passing a dict to From the requests docs:
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 |
Beta Was this translation helpful? Give feedback.
But you are. Passing a dict to
data
will cause it to be form encoded.From the requests docs:
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 thejson
parameter instead), or by setting the appropriate content-type in your handler so…