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

Caught an error from batch translate

Open leons1767 opened this issue 1 year ago • 8 comments

Hi @AidanWelch

I caught a new error from the below codes.

trInput is an array for batch translation.

It doesn't happen all the time, maybe 1 out of 4 or 5 times. Even when all the variable values are exactly the same for all the 4 or 5 times.

    const translation = await translate(trInput, {from: userLanguage, to: addHelperLanguage && helperLanguage, autoCorrect: true})
                                .catch((error) => {
                                    console.error('translate| translate-google-api-x error: ', error.message)
                                    throw error
                                });

Error caught in below

translate| translate-google-api-x error:  Cannot read properties of null (reading '1')
Url: https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&source-path=%2F&f.sid=3998618730767360818&bl=boq_translate-webserver_20230409.08_p0&hl=en-US&soc-app=1&soc-platform=1&soc-device=1&_reqid=7749&rt=c

The value returned from the Url in the error in below

)]}'

103
[["er",null,null,null,null,405,null,null,null,9],["di",17],["af.httprm",17,"-2930294764364961249",6]]
25
[["e",4,null,null,139]]

leons1767 avatar Apr 11 '23 10:04 leons1767

I'm able to replicate a similar error by spamming thousands of requests in quick succession responding with:

)]}'

105
[["er",null,null,null,null,400,null,null,null,3],["di",17],["af.httprm",17,"-8356414571367733663",103]]
25
[["e",4,null,null,141]]

I would say just try varying requests, as one of the test unit tests is 1000 requests and it doesn't have any issues. Also don't send 1000+ at the exact same time. You can also try using a proxy.

AidanWelch avatar Apr 11 '23 11:04 AidanWelch

Thanks @AidanWelch

I only sent 2 identical sentences in the array, to translate to different languages. I guess I will need a retry bloc.

leons1767 avatar Apr 11 '23 11:04 leons1767

Huh, that is weird maybe Google is changing their rate limits. You can also try calling with forceBatch: false if you're just trying individual strings. So that it at least spreads out your requests across endpoints.

AidanWelch avatar Apr 11 '23 11:04 AidanWelch

I get a similar issue with an empty string.

abhinandanudupa avatar Apr 13 '23 14:04 abhinandanudupa

I get a similar issue with an empty string.

Interesting, that doesn't seem breaking though

AidanWelch avatar Apr 13 '23 21:04 AidanWelch

Yes, it is not breaking but it can be hard to figure the reason. So, I have raised a PR which can help in such a situation for this situation. It can be helpful when the user unknowingly inputs empty strings.

abhinandanudupa avatar Apr 14 '23 02:04 abhinandanudupa

Can you see if updating to v10.6.5 helps with the error logging of your issue?

AidanWelch avatar May 22 '23 13:05 AidanWelch

The error logging works, but it seems like batch requests are failing too often, it may be to do with the init. Will investigate

AidanWelch avatar May 29 '23 18:05 AidanWelch