Google NLP authentication/call 问题
Google NLP authentication/call issue
我正在开发一个 MVC 网络应用程序,它使用 Google Natural Language Processing API 来解析来自用户的不同输入。
我已经成功使用并实施了 API 操作,只要我 运行 在我的本地计算机上应用程序,一切都正常。但是,一旦我发布一个版本并将其上传到服务器上,我就会在调用 API 方法(例如 AnalyzeSentiment)时收到以下错误:
Status(StatusCode=Unauthenticated, Detail="Getting metadata from plugin failed with error: Exception occured in metadata credentials plugin.")
借助 post 的答案: 我能够进一步了解错误的详细信息(使用 gRCP):
An error occurred while sending the request.
Stacktrace: at Google.Apis.Http.ConfigurableMessageHandler.<SendAsync>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.ServiceCredential.<GetAccessTokenForRequestAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.ServiceAccountCredential.<GetAccessTokenForRequestAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Auth.GoogleAuthInterceptors.<>c__DisplayClass2_0.<<FromCredential>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Core.Internal.NativeMetadataCredentialsPlugin.<GetMetadataAsync>d__11.MoveNext()
这似乎是一个身份验证问题,所以我仔细检查了 jsonKey 文件,没有问题。请注意,我使用代码在环境变量中设置凭据:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonPath);
并使用以下方式对其进行验证:
Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")
调用如下:
private AnalyzeSentimentResponse AnalyzeSentiment(string statement)
{
GrpcEnvironment.SetLogger(new MyLogger());
var client = LanguageServiceClient.Create();
var response = client.AnalyzeSentiment(new Document()
{
Content = statement,
Type = Document.Types.Type.PlainText
});
return response;
}
无法弄清楚为什么当我 运行 它在我的本地机器上工作正常,而当它部署在服务器上时却失败了。上述服务器也没有任何限制。
结果:
GoogleCredential.GetApplicationDefaultAsync().Result.UnderlyingCredential.GetType()
是:
Google.Apis.Auth.OAuth2.ServiceAccountCredential
注意:服务器是我们自己的(WindowsServer 2012R2)
根据@JonSkeet 的建议,我将代码复制到控制台应用程序中并执行了调用。不幸的是,问题仍然存在。我接下来做的是将控制台应用程序移动到另一台服务器上,它在那里工作。
所以,这确实是服务器的问题,可能缺少某些功能(防火墙被禁用)。网络部门正在检查它,而我已经在另一台服务器上部署了我的 Web 应用程序。
更新:服务器出现问题,未安装某些必需的框架功能。该问题已通过将部署移动到另一台服务器得到解决。
我正在开发一个 MVC 网络应用程序,它使用 Google Natural Language Processing API 来解析来自用户的不同输入。
我已经成功使用并实施了 API 操作,只要我 运行 在我的本地计算机上应用程序,一切都正常。但是,一旦我发布一个版本并将其上传到服务器上,我就会在调用 API 方法(例如 AnalyzeSentiment)时收到以下错误:
Status(StatusCode=Unauthenticated, Detail="Getting metadata from plugin failed with error: Exception occured in metadata credentials plugin.")
借助 post 的答案:
An error occurred while sending the request.
Stacktrace: at Google.Apis.Http.ConfigurableMessageHandler.<SendAsync>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.ServiceCredential.<GetAccessTokenForRequestAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.ServiceAccountCredential.<GetAccessTokenForRequestAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Auth.GoogleAuthInterceptors.<>c__DisplayClass2_0.<<FromCredential>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Core.Internal.NativeMetadataCredentialsPlugin.<GetMetadataAsync>d__11.MoveNext()
这似乎是一个身份验证问题,所以我仔细检查了 jsonKey 文件,没有问题。请注意,我使用代码在环境变量中设置凭据:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonPath);
并使用以下方式对其进行验证:
Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")
调用如下:
private AnalyzeSentimentResponse AnalyzeSentiment(string statement)
{
GrpcEnvironment.SetLogger(new MyLogger());
var client = LanguageServiceClient.Create();
var response = client.AnalyzeSentiment(new Document()
{
Content = statement,
Type = Document.Types.Type.PlainText
});
return response;
}
无法弄清楚为什么当我 运行 它在我的本地机器上工作正常,而当它部署在服务器上时却失败了。上述服务器也没有任何限制。
结果:
GoogleCredential.GetApplicationDefaultAsync().Result.UnderlyingCredential.GetType()
是:
Google.Apis.Auth.OAuth2.ServiceAccountCredential
注意:服务器是我们自己的(WindowsServer 2012R2)
根据@JonSkeet 的建议,我将代码复制到控制台应用程序中并执行了调用。不幸的是,问题仍然存在。我接下来做的是将控制台应用程序移动到另一台服务器上,它在那里工作。
所以,这确实是服务器的问题,可能缺少某些功能(防火墙被禁用)。网络部门正在检查它,而我已经在另一台服务器上部署了我的 Web 应用程序。
更新:服务器出现问题,未安装某些必需的框架功能。该问题已通过将部署移动到另一台服务器得到解决。