python - Django - Docker - The Application Default Credentials are not available -


i use google cloud sdk django project in docker container. let's assume use

from google.cloud import vision google.cloud.vision import types 

when install google-cloud using requirements.txt file error shown below. on local machine without container works properly. have idea how can solve this?

django_1 | oauth2client.client.applicationdefaultcredentialserror: application default credentials not available. available if running in google compute engine. otherwise, environment variable google_application_credentials must defined pointing file defining credentials. see https://developers.google.com/accounts/docs/application-default-credentials more information.

update work on macbook , found on this website this:

docker run --rm -it -v ~/.config/gcloud:/.config/gcloud google/cloud-sdk 

at moment errors shown below. ideas how can solve this?

django_1  | traceback (most recent call last): django_1  |   file "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner django_1  |     response = get_response(request) django_1  |   file "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response django_1  |     response = self.process_exception_by_middleware(e, request) django_1  |   file "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response django_1  |     response = wrapped_callback(request, *callback_args, **callback_kwargs) django_1  |   file "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view django_1  |     return view_func(*args, **kwargs) django_1  |   file "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view django_1  |     return self.dispatch(request, *args, **kwargs) django_1  |   file "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch django_1  |     response = self.handle_exception(exc) django_1  |   file "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception django_1  |     self.raise_uncaught_exception(exc) django_1  |   file "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch django_1  |     response = handler(request, *args, **kwargs) django_1  |   file "/code/backend/views.py", line 23, in django_1  |     client = vision.imageannotatorclient() django_1  |   file "/usr/local/lib/python3.6/site-packages/google/cloud/gapic/vision/v1/image_annotator_client.py", line 147, in __init__ django_1  |     ssl_credentials=ssl_credentials) django_1  |   file "/usr/local/lib/python3.6/site-packages/google/gax/grpc.py", line 106, in create_stub django_1  |     credentials = _grpc_google_auth.get_default_credentials(scopes) django_1  |   file "/usr/local/lib/python3.6/site-packages/google/gax/_grpc_google_auth.py", line 62, in get_default_credentials django_1  |     credentials, _ = google.auth.default(scopes=scopes) django_1  |   file "/usr/local/lib/python3.6/site-packages/google/auth/_default.py", line 282, in default django_1  |     raise exceptions.defaultcredentialserror(_help_message) django_1  | google.auth.exceptions.defaultcredentialserror: not automatically determine credentials. please set google_application_credentials or django_1  | explicitly create credential , re-run application. more django_1  | information, please see django_1  | https://developers.google.com/accounts/docs/application-default-credentials. 

the issue mounting folder / instead of /root/ config checked for

change

docker run --rm -it -v ~/.config/gcloud:/.config/gcloud google/cloud-sdk 

to

docker run --rm -it -v ~/.config/gcloud:/root/.config/gcloud google/cloud-sdk 

if use docker-compose add yaml of particular server

volumes:   - ~/.config/gcloud:/root/.config/gcloud 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -