'Disable warning when using end user credentials in GCP scripts
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?
Solution 1:[1]
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>
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KJH |
| Solution 2 | cryanbhu |
