Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

CustomVisionQuickstart.py uses wrong endpoint for predictor client config

未关闭
#295 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

打开 cognitive-services-quickstart-code/python/CustomVision/ObjectDetection/CustomVisionQuickstart.py,并将其 predictor client 配置与 issue 中显示的单独 prediction endpoint 和 key 进行比较。使用列出的 resource 值运行 object-detection quickstart,并确认检测返回结果而不是 Unauthorized。检查链接的 image-classification 和 object-detection 文档,确认其中的配置指导是否一致。

由索引模型根据 Issue 内容生成。

描述

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:


主要语言
Jupyter Notebook
星标
388
派生
555
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure-Samples/cognitive-services-quickstart-code 的其他 Issue

查看 Azure-Samples/cognitive-services-quickstart-code 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。