azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (InvalidRequest) Invalid request has been sent.

Francesco Teodori 0 Reputation points
2023-12-19T10:10:25.91+00:00
import osimport ioimport jsonfrom azure.cognitiveservices.vision.face import FaceClientfrom msrest.authentication import CognitiveServicesCredentialsimport requestsfrom PIL import Image, ImageDraw, ImageFont"""Example 5. Check if a perosn in differnet images are the same perosn"""API_KEY = '3e4c9517413a4893a230940f72672c03'ENDPOINT = 'https://vivekagoogly.cognitiveservices.azure.com/'face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(API_KEY))img_source = open(r"F:\Work_Folders\Temp_File\IMAGES\Screenshot 2023-12-17 105513.png", 'rb')response_face_source = face_client.face.detect_with_stream(image=img_source, detection_model='detection_01',                                                           recognition_model='recognition_04',)


F:\PythonProject\myvenv\Scripts\python.exe F:\PythonProject\Work_Sheet.py 
Traceback (most recent call last):
  File "F:\PythonProject\Work_Sheet.py", line 17, in <module>
    response_face_source = face_client.face.detect_with_stream(image=img_source, detection_model='detection_01',
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\PythonProject\myvenv\Lib\site-packages\azure\cognitiveservices\vision\face\operations\_face_operations.py", line 782, in detect_with_stream
    raise models.APIErrorException(self._deserialize, response)
azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (InvalidRequest) Invalid request has been sent.

Process finished with exit code 1
Azure Face
Azure Face
An Azure service that provides artificial intelligence algorithms that detect, recognize, and analyze human faces in images.
165 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2023-12-19T10:10:25.91+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error message you are receiving indicates that an invalid request has been sent. Without more information, it is difficult to determine the exact cause of the error. However, it is possible that the issue could be related to the format or content of the image being passed to the detect_with_stream method. You may want to double-check that the image is in a supported format and that it meets the requirements of the Face API.

    Unfortunately, the provided context does not contain enough information to provide a more specific answer. If you continue to experience issues, you may want to consult the Microsoft Azure SDK for Python documentation or contact Microsoft support for further assistance.


    References:

    0 comments No comments

  2. romungi-MSFT 46,751 Reputation points Microsoft Employee
    2023-12-19T12:38:30.0266667+00:00

    @Francesco Teodori Is your subscription whitelisted to use the face API? As per documentation:

    Face service access is limited based on eligibility and usage criteria in order to support our Responsible AI principles. Face service is only available to Microsoft managed customers and partners. Use the Face Recognition intake form to apply for access. For more information, see the Face limited access page.

    If you have not been whitelisted and if you call the API then the most likely error that you see is an invalid request error as seen in your response.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.