[英]Grpc.Core.RpcException: 'Status(StatusCode=“Unavailable”, Detail=“Empty update”,
[英]C# Program saving data to Google FirestoreDB fails on some computers (StatusCode=Unavailable; grpc_status: 14)
我有一個 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:\n\n" + 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 和有線連接測試)。 It pings fine google.com, accounts.google.com, oauth2.googleapis.com, www.googleapis.com . 我還禁用了 Windows 防火牆,這沒什么區別。 這發生在運行 Windows 7 和 Windows 10 的計算機上。
使用相同的互聯網連接,運行相同程序的其他計算機一切正常。
為什么 GRPC 調用在某些計算機上不起作用? 不知道我還能檢查/嘗試什么。 謝謝!
事實證明,問題在於出現問題的計算機中的時區不正確。
如果錯誤消息更具描述性,這將更容易識別,因為計算機確實與 Google 的服務器有網絡連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.