Google Cloud - Wrong project id being used from di

2019-07-09 23:29发布

Despite running gcloud auth application-default login and gcloud config set core/project CORRECT_PROJECT_ID the project keeps defaulting to an incorrect project id:

gcloud config list
[core]
account = CORRECT_EMAIL
disable_usage_reporting = True
project = CORRECT_PROJECT_ID

Your active configuration is: [default]

I can successfully run the sample code from the tutorial (below) if I run in the terminal export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

However, I didn't want to have to do this every time, so I ran the command:

gcloud auth application-default login

This opened a browser with a list of my gmail accounts, and even though I selected the correct account, the success window went to a different gmail account. So then I tried it in an incognito window, and it worked.

However, running npm start resulted in the following error:

ERROR: { Error: 7 PERMISSION_DENIED: Cloud Natural Language API has not been used in project WRONG_PROJECT_ID before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=WRONG_PROJECT_ID then retry.

Then I ran gcloud config set core/project CORRECT_PROJECT_ID and got the message Updated property [core/project].

When I run npm start I get the same message:

ERROR: { Error: 7 PERMISSION_DENIED: Cloud Natural Language API has not been used in project WRONG_PROJECT_ID before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=WRONG_PROJECT_ID then retry.

I tried gcloud auth login and got the following message (after I authenticated in an incognito window):

WARNING: `gcloud auth login` no longer writes application default credentials.
If you need to use ADC, see:
  gcloud auth application-default --help

You are now logged in as [CORRECT EMAIL ADDRESS].
Your current project is [CORRECT_PROJECT_ID].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID

1条回答
干净又极端
2楼-- · 2019-07-10 00:01

I have a few suggestions that may correct this behaviour.

1) Clear your web browser cache & cookies. Then run "gcloud auth application-default login"

2) Try re-installing the gcloud toolkit.

3) Try unsetting the project in your config first, then set the project to the correct project. i.e.

gcloud config unset project WRONG_PROJECT_ID
gcloud config set project CORRECT_PROJECT_ID

4) Check the “CLOUDSDK_CORE_PROJECT” environment variable. Set it to the correct project if it is not already.

5) Try re-running “gcloud init”

6) You can find your application default credentials in

Linux: ~/.config/gcloud/application_default_credentials.json

Windows: C:\Users\%username%\AppData\Roaming\gcloud\credentials

You can delete the file, & regenerate it using commands you had mentioned in your question such as “gcloud auth default-credentials login”

We need to find where npm start is getting its credentials from. Once we figure that out, we can figure out how to change it, & understand why it’s looking there etc.

Are you able to find the config file to see where it is looking for credentials? Is npm start the entire command? I’m not too familiar with Node JS. I’m not sure why it is trying to use Natural Language API. You also mentioned a tutorial but I think you may have forgotten to include it in your question. Which tutorial are you referring to?

查看更多
登录 后发表回答