1

I am running some scripts to do some ad-hoc jobs in GCP, using the Python client libraries.
These are ad-hoc and thus I believe they should be run on my end user credentials instead of a service account.

I keep seeing this warning and it makes it hard to debug my script standard output:

UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun `gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see https://cloud.google.com/docs/authentication/

I did the suggested gcloud auth application-default login but the same warning message still appears repeatedly.

How do I disable this warning?

cryanbhu
  • 4,780
  • 6
  • 29
  • 47
  • I'm not really sure if I'm understanding your question. If you'd like to disable all warnings you could always take advantage of the [--verbosity flag](https://cloud.google.com/sdk/gcloud/reference#--verbosity) and run every command with the flag set to `error` (e.g. gcloud auth init --verbosity="error"). Running `gcloud config set core/verbosity error` would update the value on your [default configuration](https://cloud.google.com/sdk/docs/configurations#default_configuration) and all gcloud commands that you run would be using that verbosity level by default. – Daniel Ocando Nov 12 '20 at 07:33
  • If you don't find the comment above to be useful please post a minimum, reproducible example of your specific script without sharing any sensible data as well as a brief explanation of what your script does. I recommend you to through [this documentation](https://cloud.google.com/sdk/docs/scripting-gcloud) that gives some useful advise when scripting with gcloud commands. – Daniel Ocando Nov 12 '20 at 07:42
  • I think I should have mentioned, I am using the Python client library – cryanbhu Nov 12 '20 at 10:54
  • Editing your post to include a minimum reproducible example of your script code might be of use! The [Python client libraries](https://cloud.google.com/apis/docs/client-libraries-explained#google_cloud_client_libraries) handle all the low level authentication based on environment variables or pointing to a file with the specific credentials for a service account. Are you using [google-auth¶](https://googleapis.dev/python/google-auth/latest/index.html) – Daniel Ocando Nov 12 '20 at 12:12
  • @DanielOcando what happened to my comment? Hmmm – cryanbhu Nov 18 '20 at 01:17
  • To anyone coming to this question, if you wish to resolve that specific warning and not **disable all warnings** ignore the suggestions made by @DanielOcando above and check out the answers. – cryanbhu Nov 18 '20 at 01:29

2 Answers2

4

Have a look at the lines in the library. The message is hardcoded into the function named _warn_about_problematic_credentials (starting on line 59).

If you go deeper into the file, you can see that the warning message is displayed only if there isn't a quota project defined.

You may use the following command to add a quota project to your application-default credentials:

gcloud auth application-default set-quota-project <YOUR PROJECT ID>
KJH
  • 2,382
  • 16
  • 26
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • 1
    To complement this answer here is the relevant documentation for the [set-quota-project command](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/set-quota-project). Notice that you must first run gcloud auth application-default login in order to generate the application default credentials and the existing application default credentials must have at least the "serviceusage.services.use" permission assigned. – Daniel Ocando Nov 12 '20 at 13:43
  • This works for me. I accepted this over my answer as this is less hacky than mine. – cryanbhu Nov 16 '20 at 03:22
1

I managed to disable this simply by using a Python ignore warning option as I read here.

python3 -W ignore my_script.py

If you want to be more precise and only disable certain warnings you can try this.

cryanbhu
  • 4,780
  • 6
  • 29
  • 47