tanmuhittin / laravel-google-translate

Translate translation files to other languages using google translate or another translation api
MIT License
424 stars 71 forks source link

429 Too Many Requests from Google #7

Closed DanielMalmgren closed 5 years ago

DanielMalmgren commented 5 years ago

I just got the following crash. Feels like Google don't like the amount of requests it gets in a rapid flow? Is there some delay needed somewhere so make them happier?

   ErrorException  : Client error: `POST https://translate.google.com/translate_a/single?client=t&sl=en&dt=t&sl=sv_SE&tl=es_ES&ie=UTF-8&oe=UTF-8&multires=1&otf=0&pc=1&trs=1&ssel=0&tsel=0&kc=1&tk=982989.576691` resulted in a `429 Too Many Requests` response:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="content-type" content="te (truncated...)

  at /home/vagrant/Code/Lab/vendor/stichoza/google-translate-php/src/GoogleTranslate.php:301
    297|                     'query' => $queryUrl,
    298|                     'body'  => $queryBodyEncoded,
    299|                 ] + $this->options);
    300|         } catch (RequestException $e) {
  > 301|             throw new ErrorException($e->getMessage());
    302|         }
    303|
    304|         $body = $response->getBody(); // Get response body
    305|
DanielMalmgren commented 5 years ago

I put a full output from command here: https://pastebin.com/yvMR4SGt

My base locale is sv_SE and in this example I tried translating to es_ES. Tried other languages though, seems Google gives 429 at first call. This worked yesterday however, I was using version 0.11 then.

DanielMalmgren commented 5 years ago

Ok, I thought I'd try the Google Translation API way instead, so I set up an API key and put it in laravel_google_translate.php (just replaced the NULL with my API key encapsuled in quotes), now I get the following error instead:

array(1) {
  ["error"]=>
  array(3) {
    ["code"]=>
    int(400)
    ["message"]=>
    string(13) "Invalid Value"
    ["errors"]=>
    array(1) {
      [0]=>
      array(3) {
        ["message"]=>
        string(13) "Invalid Value"
        ["domain"]=>
        string(6) "global"
        ["reason"]=>
        string(7) "invalid"
      }
    }
  }
}

I guess it somehow doesn't like my API key, just can't understand how I would otherwise format it?

Thanks for bearing with me :-)

DanielMalmgren commented 5 years ago

Ok, turns out after some more testing that the "Invalid Value" that Google is complaining about is my language codes. Using "en" and "sv" instead of "en_US" and "sv_SE" made it work like a charm. Still not really clear though on why I had to use the API at all, why google-translate-php makes it return http 429...