【问题标题】:Microsoft Face API 1.0 Error Resource Not Found未找到 Microsoft Face API 1.0 错误资源
【发布时间】:2017-08-04 10:34:37
【问题描述】:

我正在使用 Microsoft Azure 认知服务开展人脸识别项目。不太清楚为什么我不能更正我自己的 JSON 格式错误的语法,我认为我在 6 个月前就已经确定了这一点。我想创建一个组名,所以我调用“Person Group API”,每次我按照 MS 示例进行操作时,我的代码都会出错,但是在 API 测试控制台中没有问题,这是我从 MS 站点借用的代码示例:

 { "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } }

以及在控制台模式下运行的代码:

static async void CreateGroup()
        {
            string key1 = "YourKey"; 
             // azure the one should work 
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
           client.DefaultRequestHeaders.Add
           ("Ocp-Apim-Subscription-Key", key1);

        var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/
        persongroups/{personGroupId}?" + queryString;

        HttpResponseMessage response;

        // Request body
        string groupname = "myfriends";

        string body = "{\"name\":\"" + groupname + ","+ "\"}";
        // Request body
        using (var content = new StringContent
        (body, Encoding.UTF8, "application/json"))
        {

            await client.PostAsync(uri, content)
                .ContinueWith(async responseTask =>
                {
                    var responseBody = await responseTask.Result
                    .Content.ReadAsStringAsync();
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Response: {0}", responseBody);
                    Console.WriteLine("");

                    Console.WriteLine("Group Created.... ");
                    Console.WriteLine("Hit ENTER to exit...");
                    Console.ReadKey();
                });

            response = await client.PutAsync(uri, content);
            Console.WriteLine("what is this {0}", response.ToString());
            Console.ReadKey();

        }// end of using statement 


    }// end of CreateGroup
    #endregion

我猜在这里,但我认为我的 JSON 格式再次错误,我只是不知道这次我又做错了什么。根据该站点,我需要发送给 ms 的字段名称是 'name' : 'userData' 是可选的。

【问题讨论】:

    标签: azure microsoft-cognitive


    【解决方案1】:

    您的请求 url 必须指定一个组 ID,而不是 {personGroupId}。根据spec,组 ID 必须是:

    用户提供的 personGroupId 作为字符串。有效字符包括 数字、小写英文字母、'-' 和 '_'。最大值 personGroupId 的长度为 64。

    此外,http 动词需要 PUT,而您已发出 client.PostAsync 请求。所以你需要把它改成client.PutAsync

    Microsoft 为 Face API 提供了 C# 客户端库,您可以在其中找到可用的 C# 代码。

    【讨论】:

      【解决方案2】:

      遇到类似问题,在 uri 中添加“/detect”后问题已修复。 见下文

      var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/detect
      

      还要确保订阅密钥有效。

      【讨论】:

        【解决方案3】:

        在 python 中,这对我有用。

        ENDPOINT='https://westcentralus.api.cognitive.microsoft.com'

        【讨论】:

          猜你喜欢
          • 2020-08-03
          • 1970-01-01
          • 2021-09-11
          • 1970-01-01
          • 2018-09-28
          • 2022-07-28
          • 1970-01-01
          • 2016-03-31
          • 1970-01-01
          相关资源
          最近更新 更多