首页 > 解决方案 > 为什么 Google Cloud Translate 无法提供持久性 503 服务?

问题描述

每当我向 Gcloud Translate 发出请求时,我都会收到 503 错误:“此时服务不可用”。

以下是使用 Python API 的步骤:

>>> import os
>>> from google.cloud import translate_v2 as translate
>>> source_lang_code = 'nl'
>>> target_lang_code = 'en'

>>> os.environ['GOOGLE_APPLICATION_CREDENTIALS']
'/home/Documents/translate/[..keyfilename...].json'

>>> txt = open( ifn, 'r' ).read()
>>> txt[-10:]
'tuurlijk.\n'

>>> translator = translate.Client()
>>> T = translator.translate( txt, source_language=source_lang_code, target_language=target_lang_code )

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yoozer/anaconda3/lib/python3.7/site-packages/google/cloud/translate_v2/client.py", line 268, in translate
    response = self._connection.api_request(method="POST", path="", data=data)
  File "/home/yoozer/anaconda3/lib/python3.7/site-packages/google/cloud/_http.py", line 393, in api_request
    raise exceptions.from_http_response(response)
google.api_core.exceptions.ServiceUnavailable: 503 POST https://translation.googleapis.com/language/translate/v2: The service is unavailable at this time.

标签: authenticationgcloudgoogle-translategoogle-api-python-clienthttp-status-code-503

解决方案


您的代码在这里没有问题。HTTP 503 表示它是在服务请求时出现问题的服务。你应该过一段时间再试试。

如果您查看 503 的定义,它会说:

由于临时过载或计划维护,服务器当前无法处理请求,延迟一段时间后可能会得到缓解。


推荐阅读