Azure-Samples / Azure-Samples/cognitive-services-quickstart-code
CustomVisionQuickstart.py uses wrong endpoint for predictor client config
- Dominant language
- Jupyter Notebook
- Stars
- 389
- Forks
- 556
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 1
Description
> 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
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:
- https://docs.microsoft.com/en-us/azure/cognitive-services/Custom-Vision-Service/quickstarts/image-classification?tabs=visual-studio&pivots=programming-language-python
- https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/quickstarts/object-detection?tabs=visual-studio&pivots=programming-language-python
> ---------------------------------------------------------------
Contributor guide
Assessment
This issue has not been assessed yet.