question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translate: BadRequest: "Too many text segments"

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
crwilcoxcommented, Dec 6, 2019

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.

1reaction
OpenSpacesAndPlacescommented, Apr 30, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Too many text segments" error in Google translate API
As mentioned in this documentation, the total number of strings (segments) that can be sent for translation per request is limited to 128....
Read more >
Translate API error: "Too many text segments"
Hi, What's the limit for the number of text segments that can be sent to the Google Translate API v2? I get an...
Read more >
"Too Many Text Segments" Error In Google Translate Api
Lists languages from Google Translate API #' #' Returns a list of Too many text segments|Request payload size exceeds the limit|Text too long...
Read more >
CTSX Google Translator
The CTSX Google module performs translation via the Google Cloud Translation API. ... TranslateException: Too many text segments Caused by: ...
Read more >
Re: Translate API error: "Too many text segments ...
Yes, I get the limit at 128 as well. I'll have to split the N text segments into several HTTP Requests of 128...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found