【问题标题】:gcloud authentication problem on TTS python scriptTTS python脚本上的gcloud身份验证问题
【发布时间】:2018-11-11 02:58:06
【问题描述】:

我正在关注此文档:https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries#client-libraries-install-python

我已按照说明进行操作。运行提供的 Python 代码(“创建音频数据”部分)时出现错误。

第一次尝试:

看来问题出在身份验证上。我使用 gcloud init 进行了身份验证。

C:\webDev\pycharm\TTS-Nov-\Scripts\python.exe C:/webDev/pycharm/TTS-Nov-/TTS-Main.py
C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\auth\_default.py:66: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
Traceback (most recent call last):
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\grpc\_channel.py", line 533, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\grpc\_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
    status = StatusCode.PERMISSION_DENIED
    details = "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/."
    debug_error_string = "{"created":"@1541901610.961000000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.","grpc_status":7}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/webDev/pycharm/TTS-Nov-/TTS-Main.py", line 26, in <module>
    response = client.synthesize_speech(synthesis_input, voice, audio_config)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\cloud\texttospeech_v1\gapic\text_to_speech_client.py", line 257, in synthesize_speech
    request, retry=retry, timeout=timeout, metadata=metadata)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\gapic_v1\method.py", line 139, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\retry.py", line 260, in retry_wrapped_func
    on_error=on_error,
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\retry.py", line 177, in retry_target
    return target()
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\timeout.py", line 206, in func_with_timeout
    return func(*args, **kwargs)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\grpc_helpers.py", line 61, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.
  1. 第二次尝试更新:

我跑了这个 gcloud auth activate-service-account test-2@tts-alphax-nov.iam.gserviceaccount.com --key-file="C:\webDev\keys\google-cloud\tts-alphax-nov-b101c56c70b7.json" --project=tts-alphax-nov

这导致: 已激活服务帐户凭据:[test-2@tts-alphax-nov.iam.gserviceaccount.com] 然后我再次运行 python,这是我得到的错误。

C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\auth\_default.py:66: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
Traceback (most recent call last):
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\grpc\_channel.py", line 533, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\grpc\_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
    status = StatusCode.PERMISSION_DENIED
    details = "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/."
    debug_error_string = "{"created":"@1541903472.332000000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.","grpc_status":7}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/webDev/pycharm/TTS-Nov-/TTS-Main.py", line 26, in <module>
    response = client.synthesize_speech(synthesis_input, voice, audio_config)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\cloud\texttospeech_v1\gapic\text_to_speech_client.py", line 257, in synthesize_speech
    request, retry=retry, timeout=timeout, metadata=metadata)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\gapic_v1\method.py", line 139, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\retry.py", line 260, in retry_wrapped_func
    on_error=on_error,
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\retry.py", line 177, in retry_target
    return target()
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\timeout.py", line 206, in func_with_timeout
    return func(*args, **kwargs)
  File "C:\webDev\pycharm\TTS-Nov-\lib\site-packages\google\api_core\grpc_helpers.py", line 61, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.

【问题讨论】:

  • 在命令提示符 shell 中试试这个:set GOOGLE_APPLICATION_CREDENTIALS=path_to_service_credentials.json。然后再次尝试该程序。
  • 我得到了一个稍微不同的(错误)[docs.google.com/document/d/…

标签: python authentication google-cloud-platform cloud google-authentication


【解决方案1】:

此错误消息通常在应用程序未正确验证时抛出,原因有多种,例如丢失文件、无效的凭据路径、不正确的环境变量分配等。请记住,当您在会话中设置环境变量值时,每次会话被删除时都会重置它。

基于此,我建议您验证是否正确分配了凭据文件和文件路径(避免在设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量时包含空白字符),并尝试将您的服务帐户文件直接明确指定为通过将以下 credentials 代码添加到您的解决方案中,您的代码:

from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file('<serviceAccountPath>.json')

texttospeech.TextToSpeechClient(credentials=credentials)

【讨论】:

  • 我遇到了一些问题。 Python 在某些 google 模块上出错。我将尝试发布错误
猜你喜欢
  • 1970-01-01
  • 2015-07-22
  • 1970-01-01
  • 2020-08-29
  • 2013-05-16
  • 2019-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多