首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PermissionDenied: 403请求的身份验证范围不足

PermissionDenied: 403请求的身份验证范围不足
EN

Stack Overflow用户
提问于 2019-01-16 12:04:05
回答 1查看 7.4K关注 0票数 0

为了让文本到语音转换API在GCE上的Python脚本中工作,我尝试使用在GCE下运行的以下代码:

代码语言:javascript
复制
"""Synthesizes speech from the input string of text or ssml.

Note: ssml must be well-formed according to:
    https://www.w3.org/TR/speech-synthesis/
"""

# Authorize server-to-server interactions from Google Compute Engine.
import httplib2
from oauth2client.contrib import gce

credentials = gce.AppAssertionCredentials(
  scope='https://www.googleapis.com/auth/cloud-platform')
http = credentials.authorize(httplib2.Http())

from google.cloud import texttospeech

# Instantiates a client
client = texttospeech.TextToSpeechClient()

# Set the text input to be synthesized
synthesis_input = texttospeech.types.SynthesisInput(text="This is a test. It is only a test.")

# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.types.VoiceSelectionParams(
    language_code='en-US',
    ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL)

# Select the type of audio file you want returned
audio_config = texttospeech.types.AudioConfig(
    audio_encoding=texttospeech.enums.AudioEncoding.MP3)

# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(synthesis_input, voice, audio_config)

# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
    # Write the response to the output file.
    out.write(response.audio_content)
    print('Audio content written to file "output.mp3"')

我预计会有一个名为output.mp3的文件,其中会包含“这是一个测试,它只是一个测试”的表述。

我收到:"PermissionDenied: 403请求没有足够的身份验证范围。“

我已经使用了You-Tube API,并且身份验证在此基础上工作。这里我漏掉了什么?

EN

回答 1

Stack Overflow用户

发布于 2019-01-17 05:38:53

当您在GCE实例上时,请尝试将该实例的访问范围设置为“允许对所有云API的完全访问”,然后重试。

还要检查是否正确使用了客户端库和服务帐户密钥,如2所述

[1]https://cloud.google.com/compute/docs/access/service-accounts?hl=en_US&_ga=2.55324139.-1189275507.1546438047#accesscopesiam

[2]https://cloud.google.com/text-to-speech/docs/reference/libraries

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54210257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档