machine-learning - Google Cloud AutoML 中的身份验证问题

标签 machine-learning google-cloud-platform nlp google-cloud-storage google-cloud-automl

我正在做用于实体提取的 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 :

  1. 确保为您的项目启用 AutoML API - link

  2. 创建 service account您将用于身份验证 - 服务帐户是 AutoML API 唯一可用的身份验证选项

  3. 创建并下载key file对于该服务帐户。

  4. GOOGLE_APPLICATION_CREDENTIALS 环境变量设置为您在创建服务帐户时下载的服务帐户 key 文件的路径:

    • 导出 GOOGLE_APPLICATION_CREDENTIALS= key 文件
  5. PROJECT_ID 环境变量设置为您的项目 ID。 AutoML API 调用和资源名称中包含您的项目 ID。 PROJECT_ID 环境变量提供了一种指定 ID 的便捷方法:

    • 导出 PROJECT_ID=您的项目 ID
  6. 如果您是项目的所有者,请将您的服务帐户添加到 AutoML Editor IAM 角色,并将“service-account-name”替换为您的新服务帐户的名称。例如,service-account1@myproject.iam.gserviceaccount.com:

<小时/>
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/

    相关文章:

    google-cloud-platform - Terraform:无法使用生成的 SSH key 在计算引擎 VM 上远程执行

    logging - GCP 日志路由器接收器没有将日志路由到主题?

    python - 一次使用拥抱脸面膜填充超过 1 个蒙面 token 的最佳方式

    machine-learning - scikit learn如何实现输出层

    machine-learning - 使用 gensim 构建的 doc2vec 模型的 GridSearch

    algorithm - EM算法的贝叶斯信息准则计算

    python - 自动上传训练数据标签 csv 和训练处理 AutoML Vision 图像分类中的模型

    python-3.x - 使用相关和随机语料库计算 TF-IDF 单词得分

    python - 用 nltk 提取元组?

    python - 模块未找到错误: No module named 'numpy.testing.nosetester'