403请求的认证范围不足。使用应用程序默认凭据向Google Cloud NLP API发出请求时

时间:2019-03-18 18:25:24

标签: google-cloud-platform nlp

我需要从托管在已创建的Google Cloud Compute引擎实例上的python脚本向Google Cloud NLP API发出请求。因此,我遵循了完成此任务所需的步骤。

  1. 我为项目激活了NLP API,其中还包括VM实例
  2. 我下载了使用VM创建的默认服务帐户的服务密钥(作为JSON)(因为我正尝试使用Application Default Credentials进行身份验证)
  3. 我将环境变量GOOGLE_APPLICATION_CREDENTIALS设置为下载的密钥路径
  4. 为python安装了Google云客户端库

然后我通过使用google storage API运行示例来检查凭据是否正常工作,并且它返回了一个空列表,这意味着它可以正常工作。

但是在尝试调用NLP API时出现以下错误

 Traceback (most recent call last):
 File "/home/user/anaconda3/lib/python3.7/site- 
 packages/google/api_core/grpc_helpers.py", line 57, in 
 error_remapped_callable
 return callable_(*args, **kwargs)
 File "/home/user/anaconda3/lib/python3.7/site- 
 packages/grpc/_channel.py", line 549, in __call__
 return _end_unary_response_blocking(state, call, False, None)
 File "/home/user/anaconda3/lib/python3.7/site- 
 packages/grpc/_channel.py", line 466, in _end_unary_response_blocking
 raise _Rendezvous(state, None, None, deadline)
 grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
 status = StatusCode.PERMISSION_DENIED
 details = "Request had insufficient authentication scopes."
 debug_error_string = " 
 {"created":"@1552931720.241957477","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1039,"grpc_message":"Request had insufficient authentication scopes.","grpc_status":7}">

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda3/lib/python3.7/site- 
packages/google/cloud/language_v1/gapic/language_service_client.py", 
line 230, in analyze_sentiment
request, retry=retry, timeout=timeout, metadata=metadata
File "/home/user/anaconda3/lib/python3.7/site- 
packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/home/user/anaconda3/lib/python3.7/site- 
packages/google/api_core/retry.py", line 270, in retry_wrapped_func
on_error=on_error,
File "/home/user/anaconda3/lib/python3.7/site- 
packages/google/api_core/retry.py", line 179, in retry_target
return target()
File "/home/usere/anaconda3/lib/python3.7/site- 
packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/home/user/anaconda3/lib/python3.7/site- 
packages/google/api_core/grpc_helpers.py", line 59, in 
error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 Request had 
insufficient authentication scopes.

知道为什么会这样吗?

0 个答案:

没有答案