我当时在做Google Cloud AutoML演示以进行实体提取,但遇到了一些身份验证问题。我使用他们给我们的示例创建了模型,并创建并部署了我的模型。但是,我似乎似乎无法真正获得我的数据。这是我正在使用的tutorial section,这是我正在尝试运行的code

我填写了正确的project_id和model_id,但事实是,如果没有出现此错误,我似乎无法运行程序:

(venv) C:\Users\willi\Documents\machinelearningtest>py retrieveresult.py
Traceback (most recent call last):
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\grpc\_channel.py", line 824, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\grpc\_channel.py", line 726, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.PERMISSION_DENIED
        details = "The caller does not have permission"
        debug_error_string = "{"created":"@1578714342.247000000","description":"Error received from peer ipv4:172.217.14.74:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"The caller does not have permission","grpc_status":7}"
>

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

Traceback (most recent call last):
  File "retrieveresult.py", line 20, in <module>
    response = prediction_client.predict(model_full_id, payload)
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\google\cloud\automl_v1\gapic\prediction_service_client.py", line 322, in predict
    return self._inner_api_calls["predict"](
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\google\api_core\gapic_v1\method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\google\api_core\retry.py", line 281, in retry_wrapped_func
    return retry_target(
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\google\api_core\retry.py", line 184, in retry_target
    return target()
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\site-packages\google\api_core\timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "C:\Users\willi\Documents\machinelearningtest\venv\lib\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 The caller does not have permission


我无法弄清楚如何在代码中使用服务帐户来获得许可...是否可以获取一些指针?这是我第一次使用这样的东西。

最佳答案

从官方GCP documentation


确保为您的项目启用了AutoML API-link
创建用于身份验证的service account-服务帐户是AutoML API可用的唯一身份验证选项。
为该服务帐户创建并下载key file
GOOGLE_APPLICATION_CREDENTIALS环境变量设置为创建服务帐户时下载的服务帐户密钥文件的路径:


export GOOGLE_APPLICATION_CREDENTIALS=key-file

PROJECT_ID环境变量设置为您的项目ID。 AutoML API调用和资源名称中包含您的项目ID。 PROJECT_ID环境变量提供了一种方便的方法来指定ID:


export PROJECT_ID=your-project-id

如果您是项目的所有者,请将您的服务帐户添加到AutoML编辑器IAM角色,用新服务帐户的名称替换“ service-account-name”。例如,[email protected]




gcloud auth login
gcloud projects add-iam-policy-binding $PROJECT_ID \
   --member="serviceAccount:service-account-name" \
   --role="roles/automl.editor"





如果您不是项目所有者,请要求项目所有者将您的用户ID和服务帐户都添加到AutoML Editor IAM角色中

关于machine-learning - Google Cloud AutoML中的身份验证问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59691519/

10-08 20:29