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

Response code 403 (Forbidden)

Open nfriend opened this issue 5 years ago • 26 comments

I recently began receiving 403 errors when using google-translate-api. Digging in to the source a bit, this is the error that is being thrown:

{
    "message": "Response code 403 (Forbidden)",
    "host": "translate.google.com",
    "hostname": "translate.google.com",
    "method": "GET",
    "path": "/translate_a/single?client=t&sl=en&tl=fr&hl=fr&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&kc=7&q=A-Z%20Site%20Index&tk=801225.801225",
    "statusCode": 403,
    "statusMessage": "Forbidden"
}

Based on this comment, it seems that Google may have added in some rate limiting that may affect this module. Can you verify if this is the root cause?

nfriend avatar Sep 29 '18 19:09 nfriend

I changed the line 35 to client: 'gtx', instead of client: 't', and it's working for me now.

snowcxt avatar Sep 29 '18 22:09 snowcxt

@snowcxt - you're right, that change worked for me as well. Do you know why this fixes the issue?

nfriend avatar Sep 29 '18 22:09 nfriend

I was also getting 403 but for another reason. It was caused by getting incorrect token in dependency module google-translate-token, see #12 (there is already working pr).

The url above also has incorrect token: ...&tk=801225.801225 (notice equal numbers around dot).

Now the most interesting part. By the comments it looks like changing client from gtx to t allows it to work with incorrect token. I've tried the url with client=gtx and got captcha. When I passed captcha, the translation was dowloaded.

So for client=gtx token is not checked. I've tried url without token and it worked.

vitalets avatar Oct 01 '18 18:10 vitalets

So, what's the best practice? Will somebody fix this bug?

snowcxt avatar Oct 08 '18 05:10 snowcxt

So, what's the best practice? Will somebody fix this bug?

I forked google-translate-api and google-translate-token and made it work.

You can try by installing:

npm i vitalets/google-translate-api

UPDATE: Published to npm as @vitalets/google-translate-api:

npm i @vitalets/google-translate-api

See also https://github.com/matheuss/google-translate-api/issues/79#issuecomment-443428475

vitalets avatar Oct 08 '18 13:10 vitalets

Worked!

Fausto95 avatar Oct 09 '18 09:10 Fausto95

Could you publish it to npm? @vitalets

Fausto95 avatar Oct 09 '18 09:10 Fausto95

Could you publish it to npm? @vitalets

I can make a scoped package, but frankly speaking I'm not a fan of many similar packages in npm.

Hi @matheuss, could you kindly have a look on https://github.com/matheuss/google-translate-token/issues/12 and merge it? As it blocks the functionality of both packages. Thanks in advance!

vitalets avatar Oct 09 '18 10:10 vitalets

I have the same issue, using @snowcxt's solution worked for me.

BirkhoffLee avatar Oct 11 '18 17:10 BirkhoffLee

So, we don't need the google-translate-token at all?

snowcxt avatar Oct 12 '18 16:10 snowcxt

So, what's the best practice? Will somebody fix this bug?

I forked google-translate-api and google-translate-token and made it work.

You can try by installing:

npm i vitalets/google-translate-api

Ah God, finally worked!   🤦‍♂️

sadra avatar Oct 26 '18 17:10 sadra

I changed the line 35 to client: 'gtx', instead of client: 't', and it's working for me now.

This is the solution to described problem. Hooray this guy @snowcxt .

jochemstoel avatar Nov 02 '18 20:11 jochemstoel

I changed the line 35 to client: 'gtx', instead of client: 't', and it's working for me now.

Thanks a lot. You saved me. Just not sure how long will this trick work... How did you find this btw?

Songkeys avatar Nov 25 '18 23:11 Songkeys

unfortunately, still not work...

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

@vitalets your solution is no longer working for me. I forked google-translate-api as well and edited index.js line 35 as suggested, from client: 't', to client: 'gtx',. That did the trick. Hopefully the npm package will be fixed soon, but until then if you want you can just add "google-translate-api": "AlooAkbar/google-translate-api", to your package.json

AlooAkbar avatar Nov 29 '18 19:11 AlooAkbar

@snowcxt thanks. Changing client from client: 't' to client: 'gtx' did the trick. Is there any way to get the term pronunciation (in the target language) as well?

P0oOOOo0YA avatar Nov 30 '18 10:11 P0oOOOo0YA

@vitalets i rewrited your token repo in typescript and only replaced got with fetch and configstore with its electron alternative nothing more but i got an incorrect token again {name: "tk", value: "38379.38379"}.

P0oOOOo0YA avatar Nov 30 '18 11:11 P0oOOOo0YA

@P0oOOOo0YA I will re-check. Thanks!

vitalets avatar Dec 01 '18 11:12 vitalets

I've published to npm working scoped package @vitalets/google-translate-api:

npm install @vitalets/google-translate-api

After install don't forget to use scope in require:

-- const translate = require('google-translate-api');
++ const translate = require('@vitalets/google-translate-api');

Also I've added client parameter to be able to set client: 'gtx' instead of client: 't':

const translate = require('@vitalets/google-translate-api');

translate('Ik spreek Engels', { client: 'gtx', to: 'en' })
  .then(res => console.log(res.text)); // => "I speak English"

vitalets avatar Dec 01 '18 14:12 vitalets

So, what's the best practice? Will somebody fix this bug?

I forked google-translate-api and google-translate-token and made it work.

You can try by installing:

npm i vitalets/google-translate-api

UPDATE: Published to npm as @vitalets/google-translate-api:

npm i @vitalets/google-translate-api

See also #79 (comment)

Also dont forget this https://github.com/matheuss/google-translate-api/issues/79#issuecomment-443428475

mohasin69 avatar Mar 04 '19 07:03 mohasin69

So, what's the best practice? Will somebody fix this bug?

I forked google-translate-api and google-translate-token and made it work.

You can try by installing:

npm i vitalets/google-translate-api

UPDATE: Published to npm as @vitalets/google-translate-api:

npm i @vitalets/google-translate-api

See also #79 (comment)

amazing ~ What did you do?

MazsLi avatar Mar 19 '19 10:03 MazsLi

well good,it work well.

myfreax avatar May 14 '19 11:05 myfreax

Getting HTTPError: Response code 429 (Too Many Requests) after just one run on all languages.

ruscandino avatar Jun 09 '19 04:06 ruscandino

gtx no longer functions correctly.

After looking at it it seems to be a way for Google Translate Plugin to receive translations without creating a token. Thus it was never meant to be used for many translations. Vitalets as well as matheuss's forks are creating incorrect tokens which is seriously affecting functionality.

Could a team be brought together to fix such errors who know how to work with this? I would be of limited help but I do want to help, this would be a huge help.

Could you publish it to npm? @vitalets

I can make a scoped package, but frankly speaking I'm not a fan of many similar packages in npm.

Hi @matheuss, could you kindly have a look on matheuss/google-translate-token#12 and merge it? As it blocks the functionality of both packages. Thanks in advance!

ArtanisTheOne avatar Dec 22 '20 18:12 ArtanisTheOne

gtx no longer functions correctly.

After looking at it it seems to be a way for Google Translate Plugin to receive translations without creating a token. Thus it was never meant to be used for many translations. Vitalets as well as matheuss's forks are creating incorrect tokens which is seriously affecting functionality.

Could a team be brought together to fix such errors who know how to work with this? I would be of limited help but I do want to help, this would be a huge help.

I've released @vitalets/google-translate-api v5.0.0 that fixes the problem. PR with changes: #60, many thanks to @vkedwardli

vitalets avatar Jan 25 '21 18:01 vitalets

client: 'gtx'

line 35 in which file?

amitdevadhe avatar Sep 22 '23 07:09 amitdevadhe