首页 > 解决方案 > Google Cloud Storage / Speech To Text API 的 IAM 权限和身份验证问题。为什么我仍然没有权限?

问题描述

当我尝试运行 Google 的 Speech To Text API 的示例代码时收到以下错误。

代码:

from google.cloud import speech_v1p1beta1
from google.cloud.speech_v1p1beta1 import enums


def sample_recognize(storage_uri):
    """
    Performs synchronous speech recognition on an audio file

Args:
  storage_uri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE]
"""

client = speech_v1p1beta1.SpeechClient()

# storage_uri = 'gs://cloud-samples-data/speech/brooklyn_bridge.mp3'

# The language of the supplied audio
language_code = "en-US"

# Sample rate in Hertz of the audio data sent
sample_rate_hertz = 44100

# Encoding of audio data sent. This sample sets this explicitly.
# This field is optional for FLAC and WAV audio formats.
encoding = enums.RecognitionConfig.AudioEncoding.MP3
config = {
    "language_code": language_code,
    "sample_rate_hertz": sample_rate_hertz,
    "encoding": encoding,
}
audio = {"uri": storage_uri}

response = client.recognize(config, audio)
for result in response.results:
    # First alternative is the most probable result
    alternative = result.alternatives[0]
        print(u"Transcript: {}".format(alternative.transcript))
sample_recognize("gs://news2ttestbucket/untitled.mp4")

错误:

google.api_core.exceptions.PermissionDenied: 403 starting-account-950772mckg4@news2ttest-1581392888505.iam.gserviceaccount.com 没有 storage.objects.get 访问 news2ttestbucket/untitled.mp4。

关于存储桶,我已经为项目的每个级别授予了所有可以想象的权限,但它仍然拒绝访问该文件。

在此处输入图像描述

真的不明白为什么它会失败,并希望得到任何帮助,谢谢!!

标签: google-cloud-platformgoogle-cloud-storagegoogle-speech-apigoogle-iam

解决方案


In your image, you have shown that you have permissions for:

  • Editors of project
  • Owners of project
  • Viewers of project

If we look in detail at your error message:

google.api_core.exceptions.PermissionDenied:
403 starting-account-950772mckg4@news2ttest-1581392888505.iam.gserviceaccount.com
   does not have storage.objects.get access to news2ttestbucket/untitled.mp4.

We see that the identity that is requesting access to work with the bucket is called:

starting-account-950772mckg4@news2ttest-1581392888505.iam.gserviceaccount.com

Assuming that identity is neither a project Editor, Owner or Viewer then none of the permissions apply. Create a new entry by clicking "Add members" and add permissions for that identity explicitly.


推荐阅读