soimort / translate-shell

:speech_balloon: Command-line translator using Google Translate, Bing Translator, Yandex.Translate, etc.
https://www.soimort.org/translate-shell
The Unlicense
6.85k stars 388 forks source link

Show error on reaching google limits #413

Open MurzNN opened 3 years ago

MurzNN commented 3 years ago

After active use of translate-shell with google, it becomes to show empty output, instead of translation, without any errors. Seems there is some limit on Google Translate side. Will be good to detect this problem and show the error in output.

mogando668 commented 2 years ago

if you've figured out how to manually encode that query URL for a full API dump, suggest a maximum smooth rate to be 4500-bytes pre-encoded material, every 7.25 seconds, per IP address. Use something like gnu-parallel to help you regulate that flow. To be really safe, I set mine to 7.25 secs sleep after results came back from prior. (hint : Most ISPs give u both IPv4 and IPv6). No need to hassle with proxies, SmartDNS, VPN, or API-keys.

mogando668 commented 2 years ago

i'm just surprised they're still so accomodating after I've used this method to send them some 36,500,000 source-destination language pair queries … without any API key

MurzNN commented 2 years ago

I had cought this problem after about 150 calls of translate-shell in last hour, and after several hours it starts working normally again. So I decide that this is some limit on Google API side, but maybe there is any other problem. Can't reproduce this situation now. But anyway translate-shell must show the real error instead of empty output in cases like this.

skchronicles commented 2 years ago

Hello @soimort and @mogando668,

Is there currently an option or any documentation for providing an API key?

I was able to reach the API limit in less than a minute. If you are using macOS, you can reproduce the issue pretty quickly by running the command below. It just uses the built-in command say to translate a sentence and say it in the voice's defined language.

Reproduce Error macOS

while read name lang; do 
    translated=$(trans --brief :$lang \"Hello, my name is $name\"); 
    say -v $name "${translated}"; 
done < <(say -v? | gawk -v OFS='\t' '{split($2,arr,"_"); print $1, arr[1]}' | sed 's/-[a-z]*$//g')
costis-t commented 2 years ago

I accidentally sent >10k reqeusts in a few seconds and this happend to me, too. trans -dump word indicates it's a temporary problem: image

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1"><title>http://translate.googleapis.com/translate_a/single?client=gtx&amp;ie=UTF-8&amp;oe=UTF-8&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t&amp;dt=at&amp;dt=gt&amp;dt=qca&amp;sl=auto&amp;tl=en&amp;hl=en&amp;q=word</title></head>
<body style="font-family: arial, sans-serif; background-color: #fff; color: #000; padding:20px; font-size:18px;" onload="e=document.getElementById('captcha');if(e){e.focus();} if(solveSimpleChallenge) {solveSimpleChallenge(,);}">
<div style="max-width:400px;">
<hr noshade size="1" style="color:#ccc; background-color:#ccc;"><br>
<div style="font-size:13px;">
Our systems have detected unusual traffic from your computer network.  Please try your request again later.  <a href="#" onclick="document.getElementById('infoDiv0').style.display='block';">Why did this happen?</a><br><br>
<div id="infoDiv0" style="display:none; background-color:#eee; padding:10px; margin:0 0 15px 0; line-height:1.4em;">
This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the <a href="//www.google.com/policies/terms/">Terms of Service</a>. The block will expire shortly after those requests stop.<br><br>This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests.  If you share your network connection, ask your administrator for help &mdash; a different computer using the same IP address may be responsible.  <a href="//support.google.com/websearch/answer/86640">Learn more</a><br><br>Sometimes you may see this page if you are using advanced terms that robots are known to use, or sending requests very quickly.
</div><br>

IP address: 1.1.1.1<br>Time: 2022-01-31T21:54:13Z<br>URL: http://translate.googleapis.com/translate_a/single?client=gtx&amp;ie=UTF-8&amp;oe=UTF-8&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t&amp;dt=at&amp;dt=gt&amp;dt=qca&amp;sl=auto&amp;tl=en&amp;hl=en&amp;q=word<br>
</div>
</div>
</body>
</html>

It was back available after about two hours and after ~65 requests (1 request/250 msec) it was down again. I'll try to follow the limits mentioned above next time.