【发布时间】:2019-02-11 04:53:56
【问题描述】:
我正在我的 docker-compose.yml 文件中设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量。这是我的 docker-compose.yml 文件的结构:
version: "2"
services:
server:
container_name: server
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/dir1/dir2/file1.json
我的 JSON 文件位于上述目录中。在我的 python 代码中,它也作为 Docker 容器的一部分运行,我正在使用这样的 Google Speech API:
import io
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
#take speech wav file and turn it into text. return text
def transcribe_file(speech_file):
"""Transcribe the given audio file."""
client = speech.SpeechClient()
当我在上面执行时,它会抛出 google.auth.exceptions.DefaultCredentialsError: File /dir1/dir2/file1.json was not found. 的错误
我无法理解为什么当它存在于正确的目录中时它无法找到 JSON。
【问题讨论】:
标签: python docker docker-compose environment-variables google-cloud-speech