Google-cloud-python: Translate: BadRequest: "Too many text segments"

Created on 1 Jun 2018  路  7Comments  路  Source: googleapis/google-cloud-python

Code example:

from google.cloud import translate

def translate_phrases(text, target_lang='es'):
    global translate_client
    translation = translate_client.translate(
        text,
        target_language=target_lang)
    translated_texts = []
    for obj in translation:
        translated_texts.append(obj['translatedText'])
    return translated_texts    

Error obtained: BadRequest: 400 POST https://translation.googleapis.com/language/translate/v2: Too many text segments

Input: Python list of strings totaling up 819 characters.

question translation backend

Most helpful comment

I did some investigating and you can send up to 128 segments. There are also limitations on the number of overall characters, but that is well documented on failure.

Request payload size exceeds the limit: 204800 bytes.

I have requested that the error for too many segments informs you of how many segments are allowed.

All 7 comments

@randomcanary Thanks for the report. As far as I can see, the translate API quota docs don't show a per-request limit for number of charaters / segments. As a workaround, you could try breaking the list of segments up into smaller chunks.

@theacodes Who is our PoC for translate API backend issues?

/cc @beccasaurus

what's the default quota for translation api.
when I use a long list in the translate_client.translate(origin, target_language=target_language)
methods it return

 raise exceptions.from_http_response(response)
google.api_core.exceptions.BadRequest: 400 POST https://translation.googleapis.com/language/translate/v2: Too many text segments

try it yourself,Are U kidding me?

100 at a time works for me. HTH

I am seeing the same problem in C# too.

May be related to:
https://github.com/googleapis/google-cloud-dotnet/issues/2957

The problem IMO is that the limits seem arbitrary and it makes for junky and/or inefficient end code.

I did some investigating and you can send up to 128 segments. There are also limitations on the number of overall characters, but that is well documented on failure.

Request payload size exceeds the limit: 204800 bytes.

I have requested that the error for too many segments informs you of how many segments are allowed.

For reference, internal issue b/145825761

Was this page helpful?
0 / 5 - 0 ratings