-
-
Notifications
You must be signed in to change notification settings - Fork 7k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
POST with UploadFile returns 422 when called by client application #1911
Comments
Do you have python-multipart installed on your current environment? |
@ycd I am encountering this issue as well and do have python-multipart installed. |
I was using curl to hit the Fast API endpoint, and as it turns out my curl request was incorrect. After opening the Swagger docs, a suggested curl was given, which does work in this case: |
@ycd yes, I do have it installed. @zachbellay this is not much different from what Swagger docs cURL example (which does work for me) except you have added I am more hoping to know whether there is a way to get a more detailed stack trace from Uvicorn on my 422 besides |
@aretasg can you try sending a curl request with Swaggers suggested curl? |
@ycd Sure, just did that and it worked fine I have executed the following cURL which is a copy/paste from Swagger.
It seems I have no issues making a call via Swagger/curl/Postman but I do from KNIME... Bizzare. The content-type is set to multipart in KNIME so I am wondering what else could I be missing? Perhaps some other header... |
With the help of middleware, I have managed to get a bit more detailed logs. It seems the client is not sending a second file however I know it does because of the working Flask example (see my initial message).
|
Using Request directly instead of UploadFile, I can confirm that the endpoint does not receive the second file from the client - could be a parsing issue by Multipartparser class in Starlette due to unusual request formatting by the client. I don't think this a FastAPI issue any longer, so I will close with this comment. |
Thanks for the help here everyone! 👏 🙇 Thanks for reporting back and closing the issue @aretasg 👍 If you are still having issues, one way to check if the problem is related to Starlette would be to make a simple test with Quart, which is mostly compatible with Flask, so you should be able to re-use the Flask code. And as Quart uses the same ASGI spec, you could run it with Uvicorn, to also discard a problem with Uvicorn (or alternatively, try Hypercorn instead of Uvicorn). |
I have opened an issue on Starlette's repo and identified the problem and a workaround. It is due to non-standard line breaks used in the request body which is now I think it an issue of |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Example
Description
I am trying to upload two files and process them.
It works from OpenAPI/Swagger UI (/docs) and from Postman with 'Content-Type: multipart/form-data'.
However, when a KNIME workflow I have inherited is making a call the code generates 422.
I have checked the KNIME node and it also contains 'Content-Type: multipart/form-data'. You can read more about the node here.
I have tried changing headers for the past few days and about to give up but would really prefer to keep FastAPI instead of turning back to Flask. I realize it's a very KNIME specific question but I would appreciate any advice at this point.
Environment
Additional context
Before I had this piece of Flask code which did work with the client code:
The text was updated successfully, but these errors were encountered: