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.99k stars 393 forks source link

[Fatal] Null response; Google blocks all requests without access tokens #83

Closed soimort closed 8 years ago

soimort commented 9 years ago
$ trans Google           
[ERROR] Null response.
[ERROR] Oops! Something went wrong and I can't translate it for you :(

screenshot from 2015-10-03 23-07-23

soimort commented 9 years ago

Seems the block was specific to a certain range of IPs rather than applied globally. However, generating the access token (from obfuscated Javascript) would get rid of this restriction at all times. It shouldn't be too hard to do, still, a full-fledged JavaScript interpreter might be a must if we want to grab the token automatically.

soimort commented 9 years ago

Roughly it's something close to this:

Vg = "T";
cg = "K";
Kx = "|";
Eb = "&tk=";
a = [];
UJ = function(a) {
    var b = [Vg, Vg];
    b[1] = cg;
    for (var c = b = Number(window[b.join(cg)]) || 0, d = [], e = 0, f = 0; f < a.length; f++) {
        var g = a.charCodeAt(f);
        128 > g ? d[e++] = g : (2048 > g ? d[e++] = g >> 6 | 192 : (d[e++] = g >> 12 | 224, d[e++] = g >> 6 & 63 | 128), d[e++] = g & 63 | 128)
    }
    for (a = 0; a < d.length; a++) c += d[a], c += c << 10, c ^= c >>> 6;
    c += c << 3;
    c ^= c >>> 11;
    c = c + (c << 15) >>> 0;
    c %= 1E6;
    return Eb + (c.toString() + Kx + (c ^ b))
};

As of today, Google validates whether an access token has been passed in parameters, however it does not verify this token at all. So there is a pretty easy workaround...

alambike commented 9 years ago

I'd suggest as an opensouce alternative http://apertium.org. Is not so good as google translate but could be controlled by us.

avalanchy commented 9 years ago

@alambike Oh opensource cool, but don't change the topic and that it's a spam.

Looks like google changed something on their side. Trans need to be updated.

alambike commented 9 years ago

Sure, google change something by their side, but loong time ago https://cloud.google.com/translate/v2/faq#pricing

How about that everyone gets his personal api key from google, and can configure it in trans?

soimort commented 9 years ago

@alambike Personally, I would like to get an API key from Google. Running an online translation service is not cost-free and it's very sane for Google to charge users within some quota.

The problem is that Google Cloud Platform does not have an "individual" option for European users, that is to say, if you are located in one of EU countries, you must be: 1) running a business; 2) bound to a highrate VAT consequently. That's a no-go for many individual developers like me.

I'm actually interested in Apertium (not on the translation service itself but on its relevant publications). For the current issue: it should be temporarily resolved now, but I'll leave this open for a while so feel free to get in touch and come up with more suggestions.

alambike commented 9 years ago

Sure, the cost to get an api key from google seems high, but in any moment google can start to check the api tokens and ban the users, so if it could be specified somehow by the user, it would allow some peace of mind.

Regarding to apertium, I have not contributed or have relation to apertium project, I have mentioned it because I have used it in some projects, with a local installation, and just made the job, with its limitations, but it's seems an interesting project (I don't know any other) as alternative to Google or Bing propietary translation services.

tukusejssirs commented 9 years ago

I do agree with @alambike that private api tokens may solve the problem. Recently the translate-shell is working all the time which makes me open the browser to make a translation.

Switch to apertium won’t be a solution (at least not for me) as for it is not possible to use it for translation from the languages I usually use (e.g., Slovak and Czech to English and vice versa).

rr- commented 9 years ago

I think most people that (ab)use this API just want to have Google Translate accessible from CLI, not to use it for anything serious. If they limited my daily query quota to 100 I'd be plenty happy, as long as I don't have to open my browser just to translate something - especially considering their web frontend isn't very keyboard friendly.

soimort commented 8 years ago

So far, so good.