由于订阅密钥无效,访问被拒绝(Face API)
Access denied due to invalid subscription key (Face API)
我在使用 Microsoft Face 时遇到问题 API。以下是我的示例请求:
curl -v -X POST "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: 1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd" --data-ascii "{\"url\":\"http://www.mrbeantvseries.co.uk/bean3.jpg\"}"
我使用认知服务帐户中的订阅 ID,得到以下响应:
{
"error": {
"code": "Unspecified",
"message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
}
}
不确定我是否遗漏了任何内容。有人可以帮我吗?非常感谢。
您似乎输入了您的 Azure 订阅 ID?
在 Azure 门户中,您可以在 'Keys' 下找到 API 键,如下所示:
这将是一个 32 位十六进制数,没有连字符。
我也遇到过同样的问题,好像新生成的密钥有问题。要解决此问题,您实际上也可以在为 IFaceServiceClient
创建对象时添加端点。你可以看下面的代码。
private readonly IFaceServiceClient faceServiceClient = new FaceServiceClient("your key", "Your endpoint");
我运行陷入同样的问题。我阅读了 API 文档,其中说明如下。
您必须在 REST API 调用中使用与获取订阅密钥相同的区域。
首先,您必须找到订阅的位置。
为了找到您的订阅区域的位置,您必须转到标签 Location 下的 Cognitive Services -> Properties,您会找到您的订阅地区。
见下文。
其次,您必须找到正确的端点以进行调用。
例如,如果我想调用计算机视觉 API,
我的位置是美国东部,我将使用密钥 1 或 2,然后我将使用以下端点
美国东部 - https://eastus.api.cognitive.microsoft.com/face/v1.0/detect
您现在可以访问 API。
端点
https://westeurope.api.cognitive.microsoft.com/face/v1.0
终结点和订阅密钥必须一致。
查看 Microsoft 概述 了解此信息!
CesarB 是正确的。您必须先在 Azure 中创建认知服务资源,然后从中获取订阅密钥。
该区域并不总是 'westus',它实际上取决于您在创建资源时 select 所在的区域。您也可以在 Resource
的概览端点查看
我运行陷入了类似的问题。我认为它可能对某些人有帮助,所以我 post 在这里。 (顺便说一句,Azure 支持将我指向此 post 此处)
我试图 运行 通过 Azure ImageSearch 的示例文件。我指的是这些页面:
- https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/csharp
- https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/client-libraries?tabs=visualstudio&pivots=programming-language-csharp
- https://github.com/Azure-Samples/cognitive-services-dotnet-sdk-samples/blob/master/BingSearchv7/BingImageSearch/quickstart/bing-image-search-quickstart-csharp.cs
当向 Bing 搜索资源发送请求时,我收到了 404 未找到错误和 401 未授权错误 的混合,使用
Microsoft.Azure.CognitiveServices.Search.ImageSearch。我认为我的凭据或端点一定有问题。
苦苦挣扎了几个小时,通读了 posts 并与 Azure 支持成员交谈,我终于找到了问题所在:
- 我在 Azure Keys & Endpoints 网页 上分配的基本 Uri 端点不完整。 (https://api.bing.microsoft.com/)
- 示例教程页面 上的基本 Uri 端点 已过时 因为 2020.10.30 t运行 之间的位置认知服务到 Bing 搜索服务。 (https://api.cognitive.microsoft.com/bing/v7.0/images/search)
自 2021 年 9 月 22 日起,Bing 图片搜索的正确全局基础 Uri 端点是:
https://api.bing.microsoft.com/v7.0/images/search
希望这对任何人都有帮助,并为人类节省一些时间。
我在使用 Microsoft Face 时遇到问题 API。以下是我的示例请求:
curl -v -X POST "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: 1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd" --data-ascii "{\"url\":\"http://www.mrbeantvseries.co.uk/bean3.jpg\"}"
我使用认知服务帐户中的订阅 ID,得到以下响应:
{
"error": {
"code": "Unspecified",
"message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
}
}
不确定我是否遗漏了任何内容。有人可以帮我吗?非常感谢。
您似乎输入了您的 Azure 订阅 ID? 在 Azure 门户中,您可以在 'Keys' 下找到 API 键,如下所示:
这将是一个 32 位十六进制数,没有连字符。
我也遇到过同样的问题,好像新生成的密钥有问题。要解决此问题,您实际上也可以在为 IFaceServiceClient
创建对象时添加端点。你可以看下面的代码。
private readonly IFaceServiceClient faceServiceClient = new FaceServiceClient("your key", "Your endpoint");
我运行陷入同样的问题。我阅读了 API 文档,其中说明如下。
您必须在 REST API 调用中使用与获取订阅密钥相同的区域。
首先,您必须找到订阅的位置。
为了找到您的订阅区域的位置,您必须转到标签 Location 下的 Cognitive Services -> Properties,您会找到您的订阅地区。
见下文。
其次,您必须找到正确的端点以进行调用。 例如,如果我想调用计算机视觉 API, 我的位置是美国东部,我将使用密钥 1 或 2,然后我将使用以下端点 美国东部 - https://eastus.api.cognitive.microsoft.com/face/v1.0/detect
您现在可以访问 API。
端点 https://westeurope.api.cognitive.microsoft.com/face/v1.0
终结点和订阅密钥必须一致。
查看 Microsoft 概述 了解此信息!
CesarB 是正确的。您必须先在 Azure 中创建认知服务资源,然后从中获取订阅密钥。 该区域并不总是 'westus',它实际上取决于您在创建资源时 select 所在的区域。您也可以在 Resource
的概览端点查看我运行陷入了类似的问题。我认为它可能对某些人有帮助,所以我 post 在这里。 (顺便说一句,Azure 支持将我指向此 post 此处)
我试图 运行 通过 Azure ImageSearch 的示例文件。我指的是这些页面:
- https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/csharp
- https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/client-libraries?tabs=visualstudio&pivots=programming-language-csharp
- https://github.com/Azure-Samples/cognitive-services-dotnet-sdk-samples/blob/master/BingSearchv7/BingImageSearch/quickstart/bing-image-search-quickstart-csharp.cs
当向 Bing 搜索资源发送请求时,我收到了 404 未找到错误和 401 未授权错误 的混合,使用 Microsoft.Azure.CognitiveServices.Search.ImageSearch。我认为我的凭据或端点一定有问题。
苦苦挣扎了几个小时,通读了 posts 并与 Azure 支持成员交谈,我终于找到了问题所在:
- 我在 Azure Keys & Endpoints 网页 上分配的基本 Uri 端点不完整。 (https://api.bing.microsoft.com/)
- 示例教程页面 上的基本 Uri 端点 已过时 因为 2020.10.30 t运行 之间的位置认知服务到 Bing 搜索服务。 (https://api.cognitive.microsoft.com/bing/v7.0/images/search)
自 2021 年 9 月 22 日起,Bing 图片搜索的正确全局基础 Uri 端点是: https://api.bing.microsoft.com/v7.0/images/search
希望这对任何人都有帮助,并为人类节省一些时间。