【问题标题】:Can't finish "client = speech.SpeechClient()" in Google Cloud Speech无法在 Google Cloud Speech 中完成“client = speech.SpeechClient()”
【发布时间】:2019-01-02 21:19:20
【问题描述】:

谢谢你帮助我!

我刚刚设置了google cloud speech,并尝试在本网站的“Make an audio transcript request”中运行代码:https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries#client-libraries-usage-python

打开ubuntu终端后代码如下:

export GOOGLE_APPLICATION_CREDENTIALS="/home/luffy/env/Lu and-xxxxxxxxxxxx.json"

python

import io

import os

from google.cloud import speech

from google.cloud.speech import enums

from google.cloud.speech import types

client = speech.SpeechClient()

但是,当我在 Ubuntu 18.04 终端中的 python 中运行“client = speech.SpeechClient()”时,错误发生如下:

PermissionError: [Errno 13] Permission denied: '/home/luffy/env/Lu and-xxxxxxxxxxx.json'

我该如何解决这个问题?

【问题讨论】:

  • 我已经能够使用从具有Project Editor 角色的服务帐户创建的 json 密钥执行此代码。您的服务帐号(Lu 和-xxxxxxxxxxx.json 的创建来源)有什么权限?
  • 谢谢!我打开谷歌云平台-IAM 和管理-IAM,看到我的角色是所有者。我认为它比查看器和编辑器更强大。
  • 通过稍微搜索一下错误,我认为您遇到了操作错误。你能看看运行python命令的用户对json文件有读取权限吗?
  • 是的,我输入export GOOGLE_APPLICATION_CREDENTIALS="/home/luffy/env/Lu and-xxxxxxxxxxxx.json"后,然后我用echo $GOOGLE_APPLICATION_CREDENTIALS,它显示/home/luffy/env/Lu and-xxxxxxxxxxx.jso,证明我已经读过了
  • 但是当我在我的 ubuntu 上安装 anaconda3 时,它确实需要我添加另一个用户。也许我应该试试那个用户

标签: python ubuntu google-cloud-speech


【解决方案1】:

这里的问题是文件权限的操作错误。可以通过使用chmod 为文件授予正确的权限并设置正确的权限来解决它(在这种情况下,744 就足够了,因为它将允许所有用户读取凭据json 文件)。

【讨论】:

    猜你喜欢
    • 2017-09-26
    • 1970-01-01
    • 2018-11-30
    • 2020-10-16
    • 1970-01-01
    • 2017-11-01
    • 2020-09-24
    • 1970-01-01
    • 2020-07-27
    相关资源
    最近更新 更多