2

Whenever I place a request to Gcloud Translate I get a 503 error: "service unavailable at this time".

Here's the steps, using the 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.
markling
  • 1,232
  • 1
  • 15
  • 28

1 Answers1

2

Nothing wrong with your code here. HTTP 503 means it is the service that has the issue in serving the request. You should try after some time.

If you look at the definition of 503 it says:

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.

Kunal Deo
  • 2,248
  • 2
  • 18
  • 27
  • That's what it says on the tin. But this has been persistent for 12 hours. The server is not down. It's just not authorising my request. – markling Nov 22 '19 at 12:52
  • Authorization should not give you 503. I tried the sample myself and it worked for me. Can you try this from Cloud Shell? – Kunal Deo Nov 22 '19 at 12:56
  • You could double check the service account role used to perform the request. Try with the Project > Editor role and ensure that the GOOGLE_APPLICATION_CREDENTIALS env. variable has the correct path to your JSON key. But, as Kunai says, this definitely seems to be related to the service availability. Another thing that you could try is to make a cURL request to the service in order to discard the client library layer. – Mario Nov 23 '19 at 04:29