I am using a HTTPx client.
See this documentation for wrapping a FastAPI app in a HTTPx Async Client. https://fastapi.tiangolo.com/advanced/async-tests/#example
It is just, not with
block, I return the AsyncClient directly.
Everything feels fine. I can just ping my registered endpoints like:
client.post("/some/thing", json=some_thing.dict()
And it works wonderful! I can send form data with data
parameter, or body data with json
parameter.
Problem booms at when I try to test an endpoint that takes a file.
I was initially getting boundary error, which I could avoid by giving a boundary by myself, but I just deleted the header entirely, and it was fine. alright. https://stackoverflow.com/a/17438575/11210214
and now I am getting error processing the body error. Oh, no.
My endpoint and the error really looks similar to this dude implemented: https://github.com/tiangolo/fastapi/issues/2401#issue-749610783
But my problem isn't with Postman, it is with HTTPx Async Client! He gets the error reading the file before the endpoint executes, so do I. Only difference is, he nukes the file from Postman, and I do it with HTTPx Async Client.
And then I checked "cansu, are we giving the correct key?" and, yes, I do!
https://github.com/tiangolo/fastapi/issues/1536#issuecomment-640781718
My endpoint takes, lets say, a data_file = UploadFile() and, indeed, as the above issue comment guided me, I wrote it correctly. Changed files to data_file and such sort of stuff.
So, in the end, file is going to the endpoint. Form is going to the endpoint. And file can't get processed,while form is just, there.
Everyone gets boundary errors, like https://stackoverflow.com/a/67777054/11210214
https://stackoverflow.com/a/74170335/11210214
And here I am endpoint can't take an image, that is coming from Async Client! Urgh.
Deleted the headers.
Set the header (multipart-form/data) and boundary myself by calculating length of the file and form data.
Tried to use the TestClient of FastAPI, and it just straight doesn't work when pinging asynchronous endpoints saying "no current event loop". I hate testing FastAPI.
Sent many other different file types other from a simple image. Can't process a single one.