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

access denied custom vision #32015

Open AhmadManzoor opened 1 year ago

AhmadManzoor commented 1 year ago

Describe the bug Tryiong to use custom model using python and getting following error Traceback (most recent call last): File "", line 2, in File "/home/ahmad/.pyenv/versions/3.9.0/lib/python3.9/site-packages/azure/cognitiveservices/vision/customvision/prediction/operations/_custom_vision_prediction_client_operations.py", line 358, in detect_image raise models.CustomVisionErrorException(self._deserialize, response) azure.cognitiveservices.vision.customvision.prediction.models._models_py3.CustomVisionErrorException: Operation returned an invalid status code 'Access Denied'

To Reproduce Steps to reproduce the behavior: prediction_key = "3XXXXXXXXXXXXXXXXXXXXXXXX8" project_id = "XXXX-XXX-XXX-XXX-XXXXX" published_name = "Iteration2" endpoint = "https://.cognitiveservices.azure.com/" image_data = req.files["image"]

    if not image_data:
        return func.HttpResponse("Please provide an image file in the request body.", status_code=400)
    # Create a Computer Vision client
    prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key , "Content-Type": "application/octet-stream"})
    predictor = CustomVisionPredictionClient(endpoint, prediction_credentials)
    results = predictor.detect_image(project_id, published_name, req.files["image"].read())

This is how i am sending file files = {'image': <_io.BufferedReader name='/home/ahmad/Downloads/test.jpg'>} res = requests.post(furl , files=files)

Expected behavior clear and concise description of what you expected to happen. Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

pvaneck commented 1 year ago

Thanks for the feedback, As far as I am aware, the package azure-cognitiveservices-vision-customvision is no longer maintained.

@kristapratico, would you happen to have any pointers to who could better assist?

In any case, I think some things that are worth checking are:

AhmadManzoor commented 1 year ago

thank you for your quick response ensure the endpoint : i am getting this from settings page under key and endpoint getting the project id from same page also tried without "Content-Type": "application/octet-stream getting same error