google-translate-api icon indicating copy to clipboard operation
google-translate-api copied to clipboard

TooManyRequestsError

Open luandro opened this issue 2 years ago • 13 comments

You talk about this on the README, but I feel that before the re-write this didn't happen as often. Does it make any sense? And why am I hitting the limit so fast? Can't seem to get any proxies to work to circunvent the problem.

luandro avatar Nov 03 '22 11:11 luandro

You talk about this on the README, but I feel that before the re-write this didn't happen as often. Does it make any sense?

I think it's possible as we are using another route. Could you share some numbers? How many requests are you doing?

Concerning proxies - just checked 172.105.13.173 from the list, it worked. How do you try?

vitalets avatar Nov 03 '22 14:11 vitalets

Don't have exact numbers sorry. But def not over 100, and not many per second. A colleague guessed this:

I think Google can basically put any limit they want onto that, and they probably have ways of detecting that it's not coming from a browser.

Regarding the proxy I tried dynamically fetching proxies... I'll have to try again with the one you shared.

luandro avatar Nov 03 '22 14:11 luandro

Could you try send requests with changing user-agent / other headers? It's simple trick but maybe it help..

For my own tasks I've created a simple service with node-http-proxy and pass it's host as parameter to translate. It makes sense to share it in readme I think.

vitalets avatar Nov 03 '22 14:11 vitalets

Regarding the proxy I tried dynamically fetching proxies...

Please check yes in Google column

vitalets avatar Nov 03 '22 14:11 vitalets

@vitalets How would you track the number of requests? Is the rate limit by request or by characters? I was reading it was 6k characters but not sure or even how often. I'm also encountering the too many requests error, I have been testing only hence not a lot of requests but some test have been done on big strings. I was also not able to make the proxy work from the list after selecting only from the ones that say yes under Google column (roughly 111 distinct ones) with no luck. Perhaps a quick sample to get us going might help. I'm also wondering how long do those proxies lasts so I can update them accordingly. Thoughts/ideas?

bora19 avatar Jan 05 '23 06:01 bora19

Could you try send requests with changing user-agent / other headers? It's simple trick but maybe it help..

For my own tasks I've created a simple service with node-http-proxy and pass it's host as parameter to translate. It makes sense to share it in readme I think.

Can you please share code sample with modified user-agent header? Thank you

alexbash7 avatar Jan 14 '23 08:01 alexbash7

@vitalets How would you track the number of requests? Is the rate limit by request or by characters? I was reading it was 6k characters but not sure or even how often. I'm also encountering the too many requests error, I have been testing only hence not a lot of requests but some test have been done on big strings. I was also not able to make the proxy work from the list after selecting only from the ones that say yes under Google column (roughly 111 distinct ones) with no luck. Perhaps a quick sample to get us going might help. I'm also wondering how long do those proxies lasts so I can update them accordingly. Thoughts/ideas?

I've made several examples. One is to run translate with proxy. Another is to count requests until you get TooManyRequests error. I guess limit is by number of requests not by total characters. It would be great if you share what you will get.

The most interesting thing for me is how much time should pass for Google to unblock particular IP address.

vitalets avatar Jan 14 '23 09:01 vitalets

Can you please share code sample with modified user-agent header? Thank you

Here it is But in my tests it does not help with TooManyRequests error though.

vitalets avatar Jan 14 '23 10:01 vitalets

I've tried datacenter rotational proxy that changes IP every request and mobile rotational proxy that change IP every few minutes, both keep returning 'Too Many Reuqest' error. Tried delay between 10ms and 1 sec, but nothing helped.

I used previous version v8.0.0 and it worked great with everything same proxy/delay, so probably something changed in v9.0 that trigger this error.

My guess this is no IP/delay related, since error persist with new IPs, seems like google detect my request based on other data like user-agent, etc

alexbash7 avatar Jan 14 '23 10:01 alexbash7

I've tried datacenter rotational proxy that changes IP every request and mobile rotational proxy that change IP every few minutes, both keep returning 'Too Many Reuqest' error. Tried delay between 10ms and 1 sec, but nothing helped.

Hmm.. I've just made a test from my local machine. Run npx ts-node-esm examples/hit-too-many-reqs. After 400 reqs I've got TooManyRequestsError:

...
# 400: I have to learn German!
# 401: I have to learn German!
file:///Users/vitalets/projects/google-translate-api/src/index.ts:77
      return createHttpError(res.status, message);
             ^
TooManyRequestsError: Too Many Requests IP: 37.252.91.13, Time: 2023-01-15T09:13:17Z, Url: https://translate.google.com/translate_a/single?client=at&dt=t&dt=rm&dj=1

Now every request gets this error:

$ npx ts-node-esm examples/hit-too-many-reqs
Translating: Ich muss Deutsch lernen!
file:///Users/vitalets/projects/google-translate-api/src/index.ts:77
      return createHttpError(res.status, message);
             ^
TooManyRequestsError: Too Many Requests IP: 37.252.91.13, Time: 2023-01-15T09:15:34Z, Url: https://translate.google.com/translate_a/single?client=at&dt=t&dt=rm&dj=1

But if I use proxy, error disappears:

$ npx ts-node-esm examples/with-proxy 8.210.83.33:80
Using proxy: 8.210.83.33:80
Translating: Ich muss Deutsch lernen!
Result: I have to learn German!

It seems changing IP should help. I've published new version 9.1.0 that shows IP in error message (as in my code above). Could you update to the latest version and re-check with datacenter rotational proxy? In case all requests come from different IPs you will see it in error messages.

I used previous version v8.0.0 and it worked great with everything same proxy/delay, so probably something changed in v9.0 that trigger this error.

Yes, version 8 used another google api url that may have different limits policy. But there is painful bug in v8 that's why library migrated to another url.

vitalets avatar Jan 15 '23 09:01 vitalets

The agent seems not working. const agent = createHttpProxyAgent('http://103.152.112.162:80');

Can you do something like this below?

const response = await fetch(url, {
	headers: {
		'User-Agent': randomUserAgent,
		'X-Forwarded-For': randomIpAddress
	}
});

taishi55 avatar Feb 08 '23 05:02 taishi55

FetchError: request to https://translate.google.com/translate_a/single?client=at&dt=t&dt=rm&dj=1 failed, reason: connect ETIMEDOUT 117.54.114.102:80 at ClientRequest.<anonymous> (C:\Users\Radhi Sghaier\Downloads\test\node_modules\node-fetch\lib\index.js:1505:11) at ClientRequest.emit (node:events:513:28) at onerror (C:\Users\Radhi Sghaier\Downloads\test\node_modules\agent-base\dist\src\index.js:117:21) at callbackError (C:\Users\Radhi Sghaier\Downloads\test\node_modules\agent-base\dist\src\index.js:136:17) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' } } and here i'am with a timedout lol

RadhixAwp avatar Feb 14 '23 16:02 RadhixAwp

It seems like its based on a lot of factors, but the single translate endpoint is the only endpoint that has this issue, batch_execute which a lot of projects use has no usage limits.

AidanWelch avatar Mar 30 '23 09:03 AidanWelch