GCP API - 同样的“无法连接到所有地址” IAM 和 Ai Platform API 出现错误

发布于 2025-01-11 02:28:31 字数 7820 浏览 0 评论 0原文

我在尝试使用两个不同的 GCP API 库时遇到一个常见错误。上下文是我正在调用来验证资源是否正确创建 - 我不是试图创建资源,只是试图读取它们。对于这两者,我将环境变量 GOOGLE_APPLICATION_CREDENTIALS 设置为服务帐户凭据的 json 文件。我确信这意味着我的身份验证或代码中缺少一些我在文档中尚未看到的常见内容。如果有人能指出我正确的方向,那就太棒了。

示例一: 使用 Google.Cloud.Iam.Admin.V1 调用 ListRoles 方法。此代码来自以下示例:

https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Iam.Admin.V1/latest/Google.Cloud.Iam.Admin.V1.IAMClient#Google_Cloud_Iam_Admin_V1_IAMClient_ListRoles_Google_Cloud_Iam_Admin_V1_ListRolesRequest_Google_Api_Gax_Grpc_CallSettings_

代码:

23. // Create client
24. IAMClient iAMClient = IAMClient.Create();
25. // Initialize request argument(s)
26. ListRolesRequest request = new ListRolesRequest
27. {
28.     ParentAsResourceName = new UnparsedResourceName("//bigquery.googleapis.com/projects/MYPROJECTID/datasets/test_hm_bigquery"),
29.     View = RoleView.Basic,
30.     ShowDeleted = false,
31. };
32. // Make the request
33. PagedEnumerable<ListRolesResponse, Role> response = iAMClient.ListRoles(request);
34. 
35. // Iterate over all response items, lazily performing RPCs as required
36. foreach (Role item in response)
37. {
38.     // Do something with each item
39.     Console.WriteLine(item);
40. }

尝试执行第 36 行时出现错误迭代响应对象。

Grpc.Core.RpcException
  HResult=0x80131500
  Message=Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646170431.164000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":3159,"referenced_errors":[{"created":"@1646170431.164000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\lib\transport\error_utils.cc","file_line":147,"grpc_status":14}]}")
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg)
   at Grpc.Core.Calls.BlockingUnaryCall[TRequest,TResponse](CallInvocationDetails`2 call, TRequest req)
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Google.Cloud.Iam.Admin.V1.IAM.IAMClient.ListRoles(ListRolesRequest request, CallOptions options)
   at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCall`2.Sync(TRequest request, CallSettings perCallCallSettings)
   at Google.Api.Gax.Grpc.GrpcPagedEnumerable`3.<AsRawResponses>d__4.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Terraform.Tests.BigQueryDatasetTests.Test() in C:\projects\Terraform.Tests\Terraform.Tests\BigQueryDatasetTests.cs:line 36

示例二: 使用Google.Cloud.AIPlatform.V1。此代码来自

https://cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.ModelServiceClient#Google_Cloud_AIPlatform_V1_ModelServiceClient_GetModel_Google_Cloud_AIPlatform_V1_ModelName_Google_Api_Gax_Grpc_CallSettings_

19. ModelServiceClient modelServiceClient = ModelServiceClient.Create();
20. ModelName name = ModelName.FromProjectLocationModel("MYPROJECTID", "us-central1", "testhm");
21. Model response = modelServiceClient.GetModel(name);

执行行时显示错误21

Grpc.Core.RpcException
  HResult=0x80131500
  Message=Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646171341.746000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":3159,"referenced_errors":[{"created":"@1646171341.746000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\lib\transport\error_utils.cc","file_line":147,"grpc_status":14}]}")
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg)
   at Grpc.Core.Calls.BlockingUnaryCall[TRequest,TResponse](CallInvocationDetails`2 call, TRequest req)
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Google.Cloud.AIPlatform.V1.ModelService.ModelServiceClient.GetModel(GetModelRequest request, CallOptions options)
   at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCall`2.<>c__DisplayClass10_0.<WithCallSettingsOverlay>b__1(TRequest req, CallSettings cs)
   at Google.Api.Gax.Grpc.ApiCall`2.Sync(TRequest request, CallSettings perCallCallSettings)
   at Google.Cloud.AIPlatform.V1.ModelServiceClientImpl.GetModel(GetModelRequest request, CallSettings callSettings)
   at Google.Cloud.AIPlatform.V1.ModelServiceClient.GetModel(ModelName name, CallSettings callSettings)
   at Terraform.Tests.AiPlatformTests.AiModel_Test_Success() in C:\projects\Terraform.Tests\Terraform.Tests\AiPlatformTests.cs:line 21

尝试隔离问题,我也调试过,并使用Fiddler查看进出流量。无论哪种方式我都看不到任何东西。为了确保 Fiddler 设置正确,我对 github 进行了一个简单的 HTTP 调用,并且看到了该条目。所以我对发生的事情有点困惑。

I have a common error when trying to use two different GCP API libraries. The context is that I'm making calls to verify resources being created properly - I'm not trying to create resources, just trying to read them. For both, I have the environment variable GOOGLE_APPLICATION_CREDENTIALS set to the json file of the service account credentials. I'm sure this means there is some common thing is missing from my authentication or code that I haven't seen in the documentation yet. If anyone could point me in the right direction it would be awesome.

Example one:
using Google.Cloud.Iam.Admin.V1 calling the ListRoles method. This code comes from the example in:

https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Iam.Admin.V1/latest/Google.Cloud.Iam.Admin.V1.IAMClient#Google_Cloud_Iam_Admin_V1_IAMClient_ListRoles_Google_Cloud_Iam_Admin_V1_ListRolesRequest_Google_Api_Gax_Grpc_CallSettings_

Code:

23. // Create client
24. IAMClient iAMClient = IAMClient.Create();
25. // Initialize request argument(s)
26. ListRolesRequest request = new ListRolesRequest
27. {
28.     ParentAsResourceName = new UnparsedResourceName("//bigquery.googleapis.com/projects/MYPROJECTID/datasets/test_hm_bigquery"),
29.     View = RoleView.Basic,
30.     ShowDeleted = false,
31. };
32. // Make the request
33. PagedEnumerable<ListRolesResponse, Role> response = iAMClient.ListRoles(request);
34. 
35. // Iterate over all response items, lazily performing RPCs as required
36. foreach (Role item in response)
37. {
38.     // Do something with each item
39.     Console.WriteLine(item);
40. }

Error shows when executing line 36 when trying to iterate through the response object.

Grpc.Core.RpcException
  HResult=0x80131500
  Message=Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646170431.164000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":3159,"referenced_errors":[{"created":"@1646170431.164000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\lib\transport\error_utils.cc","file_line":147,"grpc_status":14}]}")
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg)
   at Grpc.Core.Calls.BlockingUnaryCall[TRequest,TResponse](CallInvocationDetails`2 call, TRequest req)
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Google.Cloud.Iam.Admin.V1.IAM.IAMClient.ListRoles(ListRolesRequest request, CallOptions options)
   at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCall`2.Sync(TRequest request, CallSettings perCallCallSettings)
   at Google.Api.Gax.Grpc.GrpcPagedEnumerable`3.<AsRawResponses>d__4.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Terraform.Tests.BigQueryDatasetTests.Test() in C:\projects\Terraform.Tests\Terraform.Tests\BigQueryDatasetTests.cs:line 36

Example two:
using Google.Cloud.AIPlatform.V1. This code comes from

https://cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.ModelServiceClient#Google_Cloud_AIPlatform_V1_ModelServiceClient_GetModel_Google_Cloud_AIPlatform_V1_ModelName_Google_Api_Gax_Grpc_CallSettings_

19. ModelServiceClient modelServiceClient = ModelServiceClient.Create();
20. ModelName name = ModelName.FromProjectLocationModel("MYPROJECTID", "us-central1", "testhm");
21. Model response = modelServiceClient.GetModel(name);

Error shows when executing line 21

Grpc.Core.RpcException
  HResult=0x80131500
  Message=Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646171341.746000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":3159,"referenced_errors":[{"created":"@1646171341.746000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\lib\transport\error_utils.cc","file_line":147,"grpc_status":14}]}")
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg)
   at Grpc.Core.Calls.BlockingUnaryCall[TRequest,TResponse](CallInvocationDetails`2 call, TRequest req)
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Google.Cloud.AIPlatform.V1.ModelService.ModelServiceClient.GetModel(GetModelRequest request, CallOptions options)
   at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCall`2.<>c__DisplayClass10_0.<WithCallSettingsOverlay>b__1(TRequest req, CallSettings cs)
   at Google.Api.Gax.Grpc.ApiCall`2.Sync(TRequest request, CallSettings perCallCallSettings)
   at Google.Cloud.AIPlatform.V1.ModelServiceClientImpl.GetModel(GetModelRequest request, CallSettings callSettings)
   at Google.Cloud.AIPlatform.V1.ModelServiceClient.GetModel(ModelName name, CallSettings callSettings)
   at Terraform.Tests.AiPlatformTests.AiModel_Test_Success() in C:\projects\Terraform.Tests\Terraform.Tests\AiPlatformTests.cs:line 21

To try and isolate the problem, I've also debugged it and used Fiddler to see traffic to and from. I'm unable to see anything either way. Just to make sure I had Fiddler set up right I made a simple HTTP call to github and saw the entry just fine. So I'm a little baffled as to what's going on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稍尽春風 2025-01-18 02:28:31

我想我应该结束我提出的这个问题,因为我发现答案是我一直怀疑的:正如乔恩·斯基特上面指出的那样,那就是网络。客户端的环境需要更新的 SSL 证书以及需要指向该证书的多个环境变量。我花了一段时间才让客户的合适人员告诉我显示工作站应该如何配置的文档在哪里。我错误地认为这是由他们的 IT 人员在设置计算机时完成的(我正在通过 RDP 访问它)。无论如何,一切都好,结局好。 DazWilkin,感谢您为帮助我解决此问题所做的努力!

Thought I would close off this question that I posed because I found that the answer was something I suspected all along: as Jon Skeet noted above it was the network. The client's environment was such that there was an updated SSL certificate that was needed and several environment variables that needed to point to it. It took a while to get the right people at the client to tell me where the document was that showed how the workstation was supposed to be configured. I mistakenly believed this was done by their IT staff when the computer was set up (I'm RDPing into it). Anyways, all's well that ends well. DazWilkin, thank you for your efforts to help me resolve this!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文