gcloud auth application-default print-access-token gives file not found error

Viewed 3111

I'm currently trying to set up a service account to run a google cloud vision OCR sample but for some reason the print-access-token command keeps failing to find my key. I've completed the following steps 3 times already just to make sure I've followed the exact steps in the docs:

  1. Init gcloud SDK with project i had already created
  2. Enabled billing
  3. Create a JSON file containing key for service account with project owner as its role
  4. set GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\file\file.json"
  5. run gcloud auth application-default print-access-token

I've also tried using gcloud auth application-default login just to be safe as it seemed to work for others who had different issues with print access token, but still no luck.

This is the error i receive from using print-access-token

ERROR: (gcloud.auth.application-default.print-access-token) File "C:\path\file.json" was not found.

I've tried running the the code samples regardless of this and receive the following exception:

Exception in thread "AWT-EventQueue-0" com.google.api.gax.rpc.PermissionDeniedException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the vision.googleapis.com.

I haven't been able to find a solution anywhere. I understand it might be a stupid problem with an easy fix, but I'm really quite confused at the moment because I'm sure I've done everything fine so far. Thanks for any help in advance.

1 Answers

I received the message about the file was not found, but I fixed this by using the command set GOOGLE_APPLICATION_CREDENTIALS without double quotation marks for example

I recommend use paths without spaces or special characters, for example C:\creds\cred1.json

set GOOGLE_APPLICATION_CREDENTIALS=C:\path\to\file\file.json

this environment variable only applies for the current CMD window is not system wide environment variable

The command gcloud auth application-default login creates a system wide credential based on an user account that allows test some APIs, but for others like vision it is necessary to use service account credentials

To fix this issue you need to define the environment variable GOOGLE_APPLICATION_CREDENTIALS as user session or system wide environment variable

After this step, your code going to recognize the credentials stored on the environment variableGOOGLE_APPLICATION_CREDENTIALS in this case C:\path\to\file\file.json

Related