C#程序在某些计算机上将数据保存到Google FirestoreDB失败(StatusCode=不可用;grpc_st



我有一个C#程序,可以读取计算机规格并将其保存到Google FirestoreDB中。在95%的计算机中,一切都很正常。但一些计算机(找不到共同点(返回时出现了错误:

Grpc.Core.RpcException: Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")
grpc_status: 14

环境变量GOOGLE_APPLICATION_CREDENTIALS具有指向包含以下内容的keyfile.json的正确路径(从谷歌云控制台下载。删除敏感数据(:

{   "type": "service_account",   "project_id": "project-id",  
"private_key_id": "XXXXXXXXXXXX",   "private_key": "-----BEGIN PRIVATE
KEY-----XXXXXXXXXXXX---END PRIVATE KEY-----n",   "client_email":
"XXXXXX@XXXXXX.iam.gserviceaccount.com",   "client_id": "XXXXXX",  
"auth_uri": "https://accounts.google.com/o/oauth2/auth",  
"token_uri": "https://oauth2.googleapis.com/token",  
"auth_provider_x509_cert_url":
"https://www.googleapis.com/oauth2/v1/certs",  
"client_x509_cert_url":
"https://www.googleapis.com/robot/v1/metadata/x509/XXXXXX.iam.gserviceaccount.com"
}

以下是将数据保存到FirestoreDB:的C#代码

try
{
string GoogleCloudProjectId = "project-id";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", AppDomain.CurrentDomain.BaseDirectory + "keyfile.json");
FirestoreDb db = FirestoreDb.Create(GoogleCloudProjectId);
DocumentReference docRef = db.Collection("inventory").Document(systemSpecs.ItemID);
await await docRef.SetAsync(systemSpecs).ContinueWith(q =>
{
if (q.IsCompleted && !q.IsFaulted)
{
MessageBox.Show("Added successfully to inventory.", "Ok", MessageBoxButton.OK, MessageBoxImage.Information);
}
return q;
});
}
catch (Grpc.Core.RpcException rpcEx) {
MessageBox.Show(rpcEx.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);            }
catch (Exception ex)
{
MessageBox.Show(ex.GetType().ToString());
MessageBox.Show("Error:nn" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", null);
Environment.Exit(0);
}

使用NuGet(Visual Studio(提供的最新软件包版本:

Google.Api.Gax = v3.2.0
Google Api.Gax.Grpc = v3.2.0
Google Api.Gax.Grpc.GrpcCore = v3.2.0
Google.Cloud.Firestore = v2.3.0
Google.Cloud.Firestore.V1 = v2.2.0
Grpc.Auth = v2.34.0
Grpc.Core = v2.34.0
Grpc.Core.Api = v2.34.0

电脑可以上网(通过wifi和有线连接进行测试(。它ping fine google.com、accounts.google.com、oauth2.googleapis.com、www.googleapis.com。我还禁用了Windows防火墙,这没有什么不同。这种情况发生在运行Windows 7和Windows 10的计算机上。

使用相同的互联网连接,其他计算机运行相同的程序,一切都很好。

为什么GRPC调用在某些计算机上不起作用?不确定我还能检查/尝试什么。谢谢

事实证明,问题是出现问题的计算机的时区不正确。

如果错误消息更具描述性,这将更容易识别,因为计算机确实与谷歌的服务器有网络连接。

相关内容

最新更新