Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomVisionQuickstart.py uses wrong endpoint for predictor client config #295

Open
ghost opened this issue Feb 22, 2022 · 1 comment
Open

Comments

@ghost
Copy link

ghost commented Feb 22, 2022

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Run "cognitive-services-quickstart-code/python/CustomVision/ObjectDetection/CustomVisionQuickstart.py" with following info:

ENDPOINT = "TRAINING_RESOURCE_ENDPOINT"
training_key = "TRAINING_RESOURCE_API_KEY"
prediction_key = "PREDICTION_API_KEY"
prediction_resource_id = "PREDICTION_RESOURCE_ID"

Any log messages given by the failure

CustomVisionErrorException                Traceback (most recent call last)
Input In [29], in <module>
      1 with open(os.path.join (base_image_location, "test", "test_image.jpg"), mode="rb") as test_data:
----> 2     results = predictor.detect_image(project.id, publish_iteration_name, test_data)

File c:\...\venv\lib\site-packages\azure\cognitiveservices\vision\customvision\prediction\operations\_custom_vision_prediction_client_operations.py:358, in CustomVisionPredictionClientOperationsMixin.detect_image(self, project_id, published_name, image_data, application, custom_headers, raw, **operation_config)
    355 response = self._client.send(request, stream=False, **operation_config)
    357 if response.status_code not in [200]:
--> 358     raise models.CustomVisionErrorException(self._deserialize, response)
    360 deserialized = None
    361 if response.status_code == 200:

CustomVisionErrorException: Operation returned an invalid status code 'Unauthorized'

Expected/desired behavior

Returned results

OS and Version?

Windows 11 Enterprise

Versions

21H2

Mention any other details that might be useful

Fixed by changing the following:

TRAINING_ENDPOINT = "TRAINING_RESOURCE_ENDPOINT"
training_key = "TRAINING_RESOURCE_API_KEY"
PREDICTION_ENDPOINT = "PREDICTION_RESOURCE_ENDPOINT"
prediction_key = "PREDICTION_API_KEY"
prediction_resource_id = "PREDICTION_RESOURCE_ID"

credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(TRAINING_ENDPOINT, credentials)
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
predictor = CustomVisionPredictionClient(PREDICTION_ENDPOINT, prediction_credentials)

Be sure to update docs if this is indeed an issue:


@jolguk
Copy link

jolguk commented Mar 28, 2022

Just spotted the same issue and fixed it the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant