简体   繁体   English

Google AI Platform 在线预测 - 使用 REST API 时权限被拒绝

[英]Google AI Platform Online Prediction - Permission Denied when using REST API

I have created a version of a machine learning model (scikit-learn house prices example) on the Google Cloud AI Platform.我在 Google Cloud AI 平台上创建了一个机器学习版本 model(scikit-learn 房价示例)。 I am now following the instructions on this page to test it with online predictions.我现在按照此页面上的说明使用在线预测对其进行测试。 The prediction is returned perfectly when I request through gcloud, however when I try to use REST API with curl I receive a "Permission Denied" 403 error.当我通过 gcloud 请求时,预测会完美返回,但是当我尝试使用 REST API 和 curl 时,我收到“权限被拒绝”403 错误。 My request and the error response are below (I replaced the PROJECT_ID, MODEL_NAME and VERSION_NAME as needed in my request):我的请求和错误响应如下(我在请求中根据需要替换了 PROJECT_ID、MODEL_NAME 和 VERSION_NAME):

REQUEST:要求:

curl -X POST -H "Content-Type: application/json" -d @input.json \
-H "Authorization: Bearer `gcloud auth print-access-token`" \
"https://ml.googleapis.com/v1/projects/${PROJECT_ID}/models/${MODEL_NAME}/versions/${VERSION_NAME}:predict"

ERROR:错误:

{
  "error": {
    "code": 403,
    "message": "Permission denied on resource project #271903.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developer console API key",
            "url": "https://console.developers.google.com/project/271903/apiui/credential"
          }
        ]
      }
    ]
  }
}

As I understand permission should be granted through the access token requested with gcloud auth print-access-token .据我了解,应通过gcloud auth print-access-token请求的访问令牌授予权限。 I have also tried entering that command separately and copying in the token manually, but I receive the same error.我也尝试单独输入该命令并手动复制令牌,但我收到相同的错误。 I have also tried including the json data directly in the request.我还尝试在请求中直接包含 json 数据。

Does anyone know this might be happening?有谁知道这可能会发生? Any help is really appreciated!非常感谢任何帮助!

In case this is useful for anyone else, it was my mistake in the request.如果这对其他人有用,那是我在请求中的错误。 I replaced the parameters inside the curly brackets rather than replacing the whole variable (between the forward slashes).我替换了大括号内的参数,而不是替换整个变量(在正斜杠之间)。 Correcting this solves the problem and prediction now works.纠正这个问题可以解决问题,并且预测现在有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM