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

BAD_REQUEST response

Open kyotin opened this issue 6 years ago • 25 comments

When our app faced with BAD_REQUEST, it won't be back to normal.

2018-06-04T12:55:26.318090+00:00 app[schedule.1]: { Error
2018-06-04T12:55:26.318105+00:00 app[schedule.1]: at /app/node_modules/google-translate-api/index.js:105:17
2018-06-04T12:55:26.318106+00:00 app[schedule.1]: at process._tickCallback (internal/process/next_tick.js:109:7) code: 'BAD_REQUEST' }

Do we have limit on number of requests per second? Our app was working fine till it face with above error.

kyotin avatar Jun 04 '18 14:06 kyotin

Yeah I've recently been getting this issue as well

HigisBig avatar Jun 05 '18 15:06 HigisBig

Yeah I've recently been getting this issue as well

easonlovejiven avatar Jun 06 '18 04:06 easonlovejiven

node_modules/google-translate-api/index.js:105:17  at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) code: 'BAD_REQUEST'

wowdyaln avatar Jun 07 '18 14:06 wowdyaln

same here!

tonistair avatar Jun 07 '18 15:06 tonistair

The actual response code from google endpoint is 503 (Service Unavailable)

Apparantly they are now checking traffic rate and redirecting to:

https://ipv4.google.com/sorry/index?continue=https://translate.google.com/translate_a/single%3Fclient%3Dt%26sl%3Dauto%26tl%3Den%26hl%3Den%26dt%3Dat%26dt%3Dbd%26dt%3Dex%26dt%3Dld%26dt%3Dmd%26dt%3Dqca%26dt%3Drw%26dt%3Drm%26dt%3Dss%26dt%3Dt%26ie%3DUTF-8%26oe%3DUTF-8%26otf%3D1%26ssel%3D0%26tsel%3D0%26kc%3D5%26tk%3D495504.128489%26q%3Dhello&hl=en&q=EgSXUHjYGISU6dgFIhkA8aeDS9nxiL3i6-okEu2kNn24nPXxXsfwMgFy

Which Says: Our systems have detected unusual traffic from your computer network. Please try your request again later.

nadalizadeh avatar Jun 08 '18 09:06 nadalizadeh

Temporary Solution:

  1. Setup a TOR HTTP Proxy: https://www.marcus-povey.co.uk/2016/03/24/using-tor-as-a-http-proxy/
  2. Use tunnel module from node packages to pass translate traffic from tor
var tunnel = require('tunnel');
...
...
    }).then(function (url) {
        return got(url, {
        agent: tunnel.httpOverHttp({
                proxy: {
                            host: 'localhost',
                            port: 8123
                        }
                 })
        }).then(function (res) {

  1. Change tor IP address periodically

nadalizadeh avatar Jun 08 '18 11:06 nadalizadeh

@nadalizadeh Your solution sounds great! But how can I force all of the translateService's traffic to go through the tor-proxy? Per request is yes! But the translateService has its own implementation of firing requests at the google-api endpoint! It would be nice, if we can have some kind of wrapper! Do you have any hint?

davidrocket avatar Jul 15 '18 08:07 davidrocket

Same issues for me too.. How can I set a TOR proxy for a hosted bot.? LOL

mohasin69 avatar Jul 23 '18 06:07 mohasin69

Getting the same issues

codecorgiii avatar Aug 02 '18 21:08 codecorgiii

{ Error at /Users/hucheng/hooper/bytedance/project/people-fe/recruitment-web/node_modules/google-translate-api/index.js:105:17 at process._tickCallback (internal/process/next_tick.js:68:7) code: 'BAD_REQUEST' }

hooper-hc avatar Sep 11 '18 01:09 hooper-hc

this package uses got to request google translate: //add this to index.js var tunnel = require('tunnel'); var agent = tunnel.httpsOverHttp({ proxy: { host: 'localhost', port: 8123 } }); //change index.js:76 got(url,agent) //add this in tor config MaxCircuitDirtiness 10

genostack avatar Sep 18 '18 09:09 genostack

this package uses got to request google translate: //add this to index.js var tunnel = require('tunnel'); var agent = tunnel.httpsOverHttp({ proxy: { host: 'localhost', port: 8123 } }); //change index.js:76 got(url,agent) //add this in tor config MaxCircuitDirtiness 10

would you consider adding a PR for that?

jahglow avatar Sep 20 '18 09:09 jahglow

we need test this first.As in China, I found this solution not work.

genostack avatar Sep 20 '18 09:09 genostack

Getting same issue.

nvtuan305 avatar Sep 23 '18 15:09 nvtuan305

Hey. Google tightened the restrictions and now from a single IP address can make very few queries. I added the use of a proxy server (IPv4, IPv6). Maybe my solution will help you.

https://github.com/extensionsapp/translatte

const translatte = require('translatte');

// Translate string to English using proxy
translatte('Вы говорите на русском?', {
    from: 'ru',
    to: 'en',
    agents: [
        'Mozilla/5.0 (Windows NT 10.0; ...',
        'Mozilla/4.0 (Windows NT 10.0; ...',
        'Mozilla/5.0 (Windows NT 10.0; ...'
    ],
    proxies: [
        'LOGIN:[email protected]:12345',
        'LOGIN:[email protected]:54321'
    ]
}).then(res => {
    console.log(res);
}).catch(err => {
    console.error(err);
});
// { text: 'Do you speak Russian?', 
//   from: { 
//     language: { 
//       didYouMean: false, 
//       iso: 'ru' 
//     }, 
//     text: { 
//       autoCorrected: false, 
//       value: '', 
//       didYouMean: false 
//     } 
//   },
//   raw: '' }

extensionsapp avatar Sep 24 '18 19:09 extensionsapp

I don't know why but on my ubuntu laptop the API works with tor, but when on Debian VPS I get bad request, I have the same config the 2 machines, do you guys have any idea what might cause the problem?

Tahakun avatar Sep 26 '18 12:09 Tahakun

Hey. Google tightened the restrictions and now from a single IP address can make very few queries. I added the use of a proxy server (IPv4, IPv6). Maybe my solution will help you.

https://github.com/extensionsapp/translatte

const translatte = require('translatte');

// Translate string to English using proxy
translatte('Вы говорите на русском?', {
    from: 'ru',
    to: 'en',
    agents: [
        'Mozilla/5.0 (Windows NT 10.0; ...',
        'Mozilla/4.0 (Windows NT 10.0; ...',
        'Mozilla/5.0 (Windows NT 10.0; ...'
    ],
    proxies: [
        'LOGIN:[email protected]:12345',
        'LOGIN:[email protected]:54321'
    ]
}).then(res => {
    console.log(res);
}).catch(err => {
    console.error(err);
});
// { text: 'Do you speak Russian?', 
//   from: { 
//     language: { 
//       didYouMean: false, 
//       iso: 'ru' 
//     }, 
//     text: { 
//       autoCorrected: false, 
//       value: '', 
//       didYouMean: false 
//     } 
//   },
//   raw: '' }

Tried this but ended up in getting below error - "SyntaxError: Unexpected token ..." at line no "translatte/node_modules/got/source/create.js:49"

I just did 'npm install translatte' and tried your example. Do I need to do anything else?

lokeshjain09 avatar Oct 03 '18 06:10 lokeshjain09

I just did 'npm install translatte' and tried your example. Do I need to do anything else?

It seems you are using older version of node.js than required for package. Please check node -v.

vitalets avatar Oct 04 '18 09:10 vitalets

I just did 'npm install translatte' and tried your example. Do I need to do anything else?

It seems you are using older version of node.js than required for package. Please check node -v.

I am using v8.4.0 node version. And now it is throwing me below error - Error at "/home/ubuntu/workspace/Hadoop/node_modules/translatte/index.js:141:17". Code: 'BAD_REQUEST'

lokeshjain09 avatar Oct 04 '18 09:10 lokeshjain09

may be google doing some updates on translator and current interaction become outdated? node 10, just installed and got BAD_REQUEST from begining. check few vpns (my private servers in different europe datacenters) to change public ip, but same result.

abrakadobr avatar Oct 22 '18 15:10 abrakadobr

Same here, I received "BAD_REQUEST" error, What should I do?

sadra avatar Oct 25 '18 12:10 sadra

I am using this for two BoTs running under Windows. I setup a Ubuntu v18 box yesterday with NodeJs. If I Stop the Windows BoTs and move / start them on the Ubuntu computer I receive bad request. I can move the BoT back to Windows and it works fine.
Same public IP Ipv4 address for both computers.

urPlaceOrMine avatar Oct 26 '18 13:10 urPlaceOrMine

Try this solution from another issue. Maybe the reason of BAD_REQUEST is the same.

vitalets avatar Oct 30 '18 11:10 vitalets

I don't know why but on my ubuntu laptop the API works with tor, but when on Debian VPS I get bad request, I have the same config the 2 machines, do you guys have any idea what might cause the problem?

Me too. and is this issue solved?

martin-matj avatar Nov 29 '18 07:11 martin-matj

Try this solution from another issue. Maybe the reason of BAD_REQUEST is the same.

That worked perfectly. Thank you

urPlaceOrMine avatar Nov 29 '18 14:11 urPlaceOrMine