[每当我向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表示服务在请求中存在问题。一段时间后,您应该尝试一下。
如果您查看503的definition,它会说:
由于以下原因,服务器当前无法处理请求临时超载或计划维护,这很可能是经过一段时间的延迟后缓解。