0
votes

I have created a version of a machine learning model (scikit-learn house prices example) on the Google Cloud AI Platform. 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. My request and the error response are below (I replaced the PROJECT_ID, MODEL_NAME and VERSION_NAME as needed in my request):

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. 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.

Does anyone know this might be happening? Any help is really appreciated!

1

1 Answers

2
votes

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.