【问题标题】:Grpc.Core.RpcException StatusCode Unavailable Channel is in state TRANSIENT_FAILUREGrpc.Core.RpcException StatusCode Unavailable Channel 处于状态 TRANSIENT_FAILURE
【发布时间】:2019-02-07 19:38:02
【问题描述】:

我正在使用 Google Vision API 来获取图像的相关标签。

 var client = ImageAnnotatorClient.Create();
 var image = Image.FromFile(@"C:\Users\Scorpio\Desktop\th.jpg");
 var response = client.DetectLabels(image); // error
 foreach (var annotation in response)
 {
     if (annotation.Description != null)
           Console.WriteLine(annotation.Description);
 }

知道如何解决这个问题吗?我尝试使用非常常见的图像,例如国旗,但仍然出错。

【问题讨论】:

  • 如果你一直有这个问题,你可以尝试使用 gRPC 的任何其他 API,例如Firestore、Speech、Language、Datastore 还是 PubSub?不知道是不是代理问题。

标签: c# google-cloud-platform google-cloud-vision


【解决方案1】:

我只是使用您的代码复制了这个场景,它运行成功。基于此,此问题可能与服务端的临时和暂时错误有关,如错误消息中所述;但是,我建议您验证是否添加了正确的库。

以下是我用来执行测试的代码,其中包括身份验证过程:

using Google.Cloud.Vision.V1;
using System;
using Grpc.Auth;
using Google.Apis.Auth.OAuth2;

namespace VisionDemo
{
    class Program
    {   
        static void Main(string[] args)
        {
            //Authenticate to the service by using Service Account
            var credential = GoogleCredential.FromFile(@"<CREDENTIALS_JSON_FILE_PATH>").CreateScoped(ImageAnnotatorClient.DefaultScopes);
            var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
            // Instantiates a client
            var client = ImageAnnotatorClient.Create(channel);
            var image = Image.FromFile(@"<IMAGE_PATH>");
            var response = client.DetectLabels(image); // error
            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                    Console.WriteLine(annotation.Description);
            }

        }
    }
}

如果您继续遇到此问题,您可以查看Issue Tracker 工具,您可以使用该工具提出Vision API,以便与 Google 技术支持团队验证此情况并检查此行为是否可以生成的项目有问题。

【讨论】:

    【解决方案2】:
     Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\Users\#YOURUSER#\source\repos\PdfToImage\credentials.json");
    

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题。 找到根本原因并修复它。

      问题是由于 Nuget 包:Grpc.Core.Api 此软件包已更新至版本:2.25.0,而 Grpc.Core 由于 Google.Api.Gax.Grpc 2.10.0 而在版本 1.22.1 被阻止

      没有什么能阻止您将 Grpc.Core.Api 更新到 2.25.0 版本,然后面临奇怪的问题 - client.Detect... 方法没有返回成功或错误,什么也没有(我没有等待 20 分钟)。

      解决方案 Grpc.Core.Api - 将版本号恢复到 1.22.1

      希望有帮助!

      【讨论】:

        猜你喜欢
        • 2021-06-07
        • 2022-01-06
        • 2021-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-21
        • 2016-09-13
        相关资源
        最近更新 更多