[英]Grpc.Core.RpcException StatusCode Unavailable Channel is in state TRANSIENT_FAILURE
I am using Google Vision API to get associated labels for an image.我正在使用 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);
}
Any idea how can we resolve this issue?知道我们如何解决这个问题吗? I tried using very common images like country flags but still it gives error.我尝试使用非常常见的图像,如国旗,但仍然出错。
I just replicate this scenario by using your code and it ran successfully.我只是使用您的代码复制了这个场景,它运行成功。 Based on this, it is possible that this issue was related to a temporary and transient error from the service side, as mentioned in the error message;基于此,此问题可能与服务端的暂时性和暂时性错误有关,如错误消息中所述; however, I recommend you to verify you are adding the correct libraries.但是,我建议您验证是否添加了正确的库。
Below is the code I used to perform the testing which includes the authentication process:下面是我用来执行测试的代码,其中包括身份验证过程:
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);
}
}
}
}
In case you continue having this issue, you could take a look the Issue Tracker tool that you can use to raise a Vision API in order to verify this scenario with the Google Technical Support Team and check if this behavior can being generated with an issue on your project.如果您继续遇到此问题,您可以查看问题跟踪器工具,您可以使用该工具提出Vision API ,以便与 Google 技术支持团队验证此场景,并检查是否可以在出现问题时生成此行为你的项目。
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\Users\#YOURUSER#\source\repos\PdfToImage\credentials.json");
I bumped into the same issue.我遇到了同样的问题。 Found the root cause and fixed it.找到根本原因并修复它。
Issue is due to Nuget package: Grpc.Core.Api This package got updated to version: 2.25.0, whereas Grpc.Core is blocked at version 1.22.1 due to Google.Api.Gax.Grpc 2.10.0问题是由于 Nuget 包:Grpc.Core.Api 此包已更新到版本:2.25.0,而 Grpc.Core 由于 Google.Api.Gax.Grpc 2.10.0 而在版本 1.22.1 中被阻止
Nothing stops you from updating Grpc.Core.Api to 2.25.0 version and then face the weird issue - client.Detect... methods not returning success or error, nothing (I didnt wait for 20 mins).没有什么能阻止你将 Grpc.Core.Api 更新到 2.25.0 版本,然后面对奇怪的问题 - client.Detect ... 方法不返回成功或错误,什么都没有(我没有等 20 分钟)。
Solution Grpc.Core.Api - bring the version number back to 1.22.1解决方案Grpc.Core.Api - 将版本号调回 1.22.1
Hope that helps!希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.