每当我向 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.
最佳答案
您的代码没有问题。 HTTP 503 表示该服务在处理请求时出现问题。你应该在一段时间后尝试。
如果你看definition 503 中写道:
The server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay.
关于authentication - 为什么 Google Cloud Translate 上的持久 503 服务不可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58993775/