我想在Docker容器中使用帶有Django項目的Google Cloud SDK。讓我們假設我想用Django - Docker - 應用程序默認憑據不可用
from google.cloud import vision
from google.cloud.vision import types
當我使用requirements.txt
文件,我得到如下圖所示的錯誤安裝google-cloud
。在沒有容器的本地機器上,它正常工作。有沒有人有一個想法,我該如何解決這個問題?
django_1 | oauth2client.client.ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
UPDATE 我的MacBook上工作,我在這個this website發現:
docker run --rm -it -v ~/.config/gcloud:/.config/gcloud google/cloud-sdk
在這一刻,我得到如下圖所示的錯誤。任何想法如何解決這個問題?
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 get
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: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
django_1 | explicitly create credential and re-run the application. For more
django_1 | information, please see
django_1 | https://developers.google.com/accounts/docs/application-default-credentials.
試試這個'搬運工運行-e 「GOOGLE_APPLICATION_CREDENTIALS = $ GOOGLE_APPLICATION_CREDENTIALS」 --rm - 它-v〜/的.config/gcloud:/配置/ gcloud谷歌/雲sdk' –
@TarunLalwani後使用你的命令有'root @ 4271b8a28802:/#',仍然是相同的錯誤。 – wahtdbogh
你可以在你的Mac上運行'env'併發布所有'google'相關的環境變量嗎?將需要專用的任何值替換爲虛擬值。 –