相关文章推荐
捣蛋的金针菇  ·  【进阶篇】Redis实战之Redisson使 ...·  6 天前    · 
飞翔的打火机  ·  在ggplot2中调整图例标题的位置和字体大 ...·  2 年前    · 
仗义的山羊  ·  Python基础教程:两种获取list中指定 ...·  2 年前    · 
有腹肌的小熊猫  ·  python - How to use ...·  2 年前    · 
呐喊的生姜  ·  经典面试题-FileSystemResour ...·  2 年前    · 
傲视众生的乌冬面  ·  druid校验连接超过15分钟?报错-问答- ...·  2 年前    · 
Code  ›  python - Python 调用 google cloud speech-to-text API 出现 503 错误 -
python config
https://segmentfault.com/q/1010000039293618
跑龙套的啄木鸟
2 年前
segmentfault segmentfault
注册登录
问答 博客 标签 活动
发现
✓ 使用“Bing”搜本站 使用“Google”搜本站 使用“百度”搜本站 站内搜索
注册登录
  1. 首页
  2. 问答
  3. python
  4. 问答详情

Python 调用 google cloud speech-to-text API 出现 503 错误

头像
antares
2 1 3
发布于
2021-02-26
更新于
2021-02-26
新手上路,请多包涵

我尝试跑了 https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries 上面的python例程:

# Imports the Google Cloud client library
from google.cloud import speech
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'key.json'
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
audio = speech.RecognitionAudio(uri=gcs_uri)
config = speech.RecognitionConfig(
    encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=16000,
    language_code="en-US",
# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)
for result in response.results:
    print("Transcript: {}".format(result.alternatives[0].transcript))

跑的时候开了 fq 软件全局代理。得到这个 503 错误:

  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\grpc\_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\grpc\_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "failed to connect to all addresses"
    debug_error_string = "{"created":"@1614347442.192000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4090,"referenced_errors":[{"created":"@1614347442.192000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":394,"grpc_status":14}]}"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 184, in retry_target
    return target()
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:/Users/98274/Desktop/carla_ppo/test_connection.py", line 22, in <module>
    response = client.recognize(config=config, audio=audio)
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\cloud\speech_v1\services\speech\client.py", line 334, in recognize
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 286, in retry_wrapped_func
    on_error=on_error,
  File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 206, in retry_target
    last_exc,
  File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x0000026B56606A68>, config {
  encoding: LINEAR16
  sample_rate_hertz: 16000
 
推荐文章
捣蛋的金针菇  ·  【进阶篇】Redis实战之Redisson使用技巧详解,干活!开发者社区
6 天前
飞翔的打火机  ·  在ggplot2中调整图例标题的位置和字体大小-腾讯云开发者社区-腾讯云
2 年前
仗义的山羊  ·  Python基础教程:两种获取list中指定元素的索引_51CTO博客_python获取某个元素的索引
2 年前
有腹肌的小熊猫  ·  python - How to use civitAI checkpoint with ControlNet - Stack Overflow
2 年前
呐喊的生姜  ·  经典面试题-FileSystemResource和ClassPathResource有何区别?_wx5d0241bb88268的技术博客_51CTO博客
2 年前
傲视众生的乌冬面  ·  druid校验连接超过15分钟?报错-问答-阿里云开发者社区-阿里云
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号