Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.59k stars 2.8k forks source link

Expected 'None' but got CognitiveServicesCredentials Instead plus InvalidResponse #25182

Closed thecowmilk closed 2 years ago

thecowmilk commented 2 years ago

Describe the bug I'm setting up a code for face recognition and when I'm making the code I get this warning while I implement the face client. face_client = FaceClient(ENDPOINT, CREDENTIALS)

After this there's this other error which causes the code to break.

response_faces = face_client.face.detect_with_stream(
    image=open(image, 'rb'),
    detection_model='detection_03',
    recognition_model='recognition_04',
    return_face_landmarks=True,
)

This is how I wanna send messages locally by stream but the problem is that whenever I run this code I get this problem:

/home/thecowmilk/dev/azure_faceapi/venv/bin/python /home/thecowmilk/dev/azure_faceapi/faceapi/starting.py
Traceback (most recent call last):
  File "/home/thecowmilk/dev/azure_faceapi/faceapi/starting.py", line 17, in <module>
    response_faces = face_client.face.detect_with_stream(
  File "/home/thecowmilk/dev/azure_faceapi/venv/lib/python3.8/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.

To Reproduce Steps to reproduce the behavior:

  1. A clean install of your OS
  2. install these libraries:
    azure-cognitiveservices-vision-face
    azure-cognitiveservices-vision-computervision
    azure-cognitiveservices-vision-customvision
    azure-cognitiveservices-formrecognizer
    pillow
    pandas
  3. Write this code:
    
    import os
    import io
    import cv2
    from azure.cognitiveservices.vision.face import FaceClient
    from azure.cognitiveservices.vision.face.operations import FaceOperations
    from msrest.authentication import CognitiveServicesCredentials
    from PIL import Image, ImageDraw, ImageFont

API_KEY = 'your_free_sub_api_key' ENDPOINT = 'your_free_sub_endpoit'' CREDENTIALS = CognitiveServicesCredentials(API_KEY) image = 'realmadrid.jpg' face_client = FaceClient(ENDPOINT, CREDENTIALS) operations = FaceOperations

response_faces = face_client.face.detect_with_stream( image=open(image, 'rb'), detection_model='detection_03', recognition_model='recognition_04', return_face_landmarks=True, )

if not response_faces: raise Exception("No face detected!")

print(f"Number of face detected {len(response_faces)}")


4. Try to run and then you have got the idea of this error

**Expected behavior**
It should have worked an returned a result
ghost commented 2 years ago

Thank you for your feedback. This has been routed to the support team for assistance.

SaurabhSharma-MSFT commented 2 years ago

@thecowmilk We are looking into it and get back to you for any additional information.

SaurabhSharma-MSFT commented 2 years ago

@thecowmilk I do not see any issues calling detect_with_stream function with both results and no results. See below - image image

Which version of the vision face library you are using?

Thanks Saurabh

thecowmilk commented 2 years ago

@SaurabhSharma-MSFT I debugged a little and I got this response back

raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(
azure.core.exceptions.DeserializationError: ("Unable to deserialize response data. Data: {'error': {'code': 'InvalidRequest', 'message': 'Invalid request has been sent.', 'innererror': {'code': 'UnsupportedFeature', 'message': 'Feature is not supported. Please apply for access at https://aka.ms/facerecognition'}}}, [DetectedFace], DeserializationError: Cannot deserialize as [DetectedFace] an object of type <class 'dict'>", DeserializationError("Cannot deserialize as [DetectedFace] an object of type <class 'dict'>"))

I don't know if it intended or not.... Also when I do send the requests with my own API Key it is forbidden for me, it return a 403. What am I doing wrong?

SaurabhSharma-MSFT commented 2 years ago

@thecowmilk This is intended as Face API falls under Limited Access features for Cognitive Services. You got this error since what you are trying to call is now limited access to them because you have not been approved to use that capability. Face service is only available to Microsoft managed customers and partners. Please use the Face Recognition intake form to apply for access- aka.ms/facerecognition. Please let me know if you have any questions. Thanks

ghost commented 2 years ago

Hi @thecowmilk. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

SaurabhSharma-MSFT commented 2 years ago

@thecowmilk We will now proceed to close this thread. If there are further questions regarding this matter, please reopen it and we will gladly continue the discussion.