google-cloud-platform - 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。
关于存储桶,我已经为项目的每个级别授予了所有可以想象的权限,但它仍然拒绝访问该文件。
真的不明白为什么它会失败,并希望得到任何帮助,谢谢!!
解决方案
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.
推荐阅读
- c++ - 类型推导失败:派生模板的 shared_ptr 到基模板作为函数参数
- angularjs - AngularJS 关于将工厂转换为提供者的建议?
- python - 制作元组的笛卡尔不起作用
- python - 作为 PC 算法的一部分,在 python 中测试条件独立性
- javascript - 如何在从 Ajax 执行的 PHP 文件中执行 JavaScript
- java - 无法通过 JAVA 运行 XSLT 并且在输出中观察到 Empty 结果
- python - 读取文件并将文件中的数据提供给函数
- ios - iOS 12 Swift 将 TrueDepth 数据保存到视频
- javascript - 为什么“clearInterval”在条件“mouseover”事件监听器中不起作用?
- node.js - 尝试编写 node.js 脚本以使用正则表达式和搜索/替换批量重命名文件