422 unprocessable entity fastapi when trying to call api to get image
See original GitHub issueI am a newbie to fastAPI. While I tried to write an API to get the uploaded image I got this error: INFO: 127.0.0.1:50702 - “POST /faces/identify HTTP/1.1” 422 Unprocessable Entity
my codes here. It very thankful if someone can help
router = APIRouter()
# Identify faces on the image
@router.post('/faces/identify')
async def web_recognize(file_upload: UploadFile = File(...)):
face_recognition_service = faceRecognition.FaceRecognition_service(faces_dict)
file = face_recognition_service.extract_image(file_upload)
if file and face_recognition_service.is_picture(file.filename):
return face_recognition_service.detect_faces_in_image(file)
else:
raise ErrorResponse(code=codes.code_files_invalid, message=messages.message_files_invalid, `status=status.HTTP_400_BAD_REQUEST)`
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Why do I get an "Unprocessable Entity" error while uploading ...
The problem is that your route is expecting 2 types of request body: request: schemas.Item. This is expecting POSTing an application/json ...
Read more >Request Files - FastAPI
To receive uploaded files, first install python-multipart . ... They all call the corresponding file methods underneath (using the internal ...
Read more >tiangolo/fastapi - Gitter
This is func call api login. But i got error HTTP 422 UNPROCESSABLE ENTITY. I tested api login with Postman and /docs, it'...
Read more >422 Unprocessable Entity - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type ...
Read more >How can i solve this error:422 (Unprocessable Entity)
You are getting a 422 because validation is failing. You can check your request in the browser's devtools to see what is being...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A response having status code 422 will have a response body that specifies the error message, please have a look at that. Also please mention from where are you making the request.
Below example code should work
Basically, you will have to make a POST request having content-type:
multipart/form-data
Dear here is my response
{ "detail": [ { "loc": [ "body", "image" ], "msg": "field required", "type": "value_error.missing" } ] }
and here is my curl in postman
curl --location --request POST 'http://localhost:8080/faces/identify' \ --form 'file=@"1.jpg"'
where the image is in working directory. I just put it there to test my api