【问题标题】:Why persistent 503 service unavailable on Google Cloud Translate?为什么 Google Cloud Translate 无法提供持久性 503 服务?
【发布时间】:2020-03-18 11:57:40
【问题描述】:

每当我向 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.

【问题讨论】:

    标签: authentication gcloud google-translate google-api-python-client http-status-code-503


    【解决方案1】:

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

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

    服务器当前无法处理请求,因为 临时超载或定期维护,这可能是 延迟一段时间后缓解。

    【讨论】:

    • 锡罐上是这么写的。但这已经持续了12个小时。服务器没有关闭。只是没有授权我的请求。
    • 授权不应该给你 503。我自己尝试了这个示例,它对我有用。你可以在 Cloud Shell 中试试这个吗?
    • 您可以仔细检查用于执行请求的服务帐户角色。尝试使用 Project > Editor 角色并确保 GOOGLE_APPLICATION_CREDENTIALS env。变量具有指向您的 JSON 密钥的正确路径。但是,正如 Kunai 所说,这似乎与服务可用性有关。您可以尝试的另一件事是向服务发出 cURL 请求以丢弃客户端库层。
    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 2011-06-26
    • 2020-11-20
    • 1970-01-01
    • 2017-05-23
    • 2018-02-15
    相关资源
    最近更新 更多