question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

422 unprocessable entity fastapi when trying to call api to get image

See original GitHub issue

I 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:open
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
NiharZanwarcommented, Jun 3, 2021

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

import requests
url = "http://localhost/faces/identify"
files = {'file_upload': open('test.jpg', 'rb')}
requests.post(url, files=files)

Basically, you will have to make a POST request having content-type: multipart/form-data

1reaction
dolong2110commented, Jun 3, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found