Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for when TKK is already rendered #78

Closed
wants to merge 3 commits into from

Conversation

Guy-Dipietro-Bose
Copy link

Randomly the TKK value is coming back already rendered. This will handle that case.

@coveralls
Copy link

Coverage Status

Coverage decreased (-8.5%) to 90.204% when pulling 7b7a0d0 on BoseCorp:master into 4865333 on ssut:master.

@coveralls
Copy link

coveralls commented Sep 20, 2018

Coverage Status

Coverage decreased (-8.5%) to 90.204% when pulling 506ec8e on BoseCorp:master into 4865333 on ssut:master.

@Guy-Dipietro-Bose
Copy link
Author

Coverage decreased most likely because the exception case will only be exercised about 5% of the time.

@Guy-Dipietro-Bose Guy-Dipietro-Bose mentioned this pull request Sep 20, 2018
@Darkblader24
Copy link

Darkblader24 commented Sep 20, 2018

Here is another version of the fix, it is a bit cleaner:

    RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
                        re.DOTALL)
    RE_RAWTKK = re.compile(r'TKK=\'([^\']*)\';',re.DOTALL)

    def __init__(self, tkk='0', session=None, host='translate.google.com'):
        self.session = session or requests.Session()
        self.tkk = tkk
        self.host = host if 'http' in host else 'https://' + host

    def _update(self):
        """update tkk
        """
        # we don't need to update the base TKK value when it is still valid
        now = math.floor(int(time.time() * 1000) / 3600000.0)
        if self.tkk and int(self.tkk.split('.')[0]) == now:
            return

        r = self.session.get(self.host)

        rawtkk = self.RE_RAWTKK.search(r.text)
        if rawtkk:
            self.tkk = rawtkk.group(1)
            return

Edit: Removed verify=False from r = self.session.get(self.host, verify=False)

@Guy-Dipietro-Bose
Copy link
Author

@Darkblader24 Yes much cleaner, updated using your solution.

@NoiseControllers
Copy link

Here is another version of the fix, it is a bit cleaner:

    RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
                        re.DOTALL)
    RE_RAWTKK = re.compile(r'TKK=\'([^\']*)\';',re.DOTALL)

    def __init__(self, tkk='0', session=None, host='translate.google.com'):
        self.session = session or requests.Session()
        self.tkk = tkk
        self.host = host if 'http' in host else 'https://' + host

    def _update(self):
        """update tkk
        """
        # we don't need to update the base TKK value when it is still valid
        now = math.floor(int(time.time() * 1000) / 3600000.0)
        if self.tkk and int(self.tkk.split('.')[0]) == now:
            return

        r = self.session.get(self.host, verify=False)

        rawtkk = self.RE_RAWTKK.search(r.text)
        if rawtkk:
            self.tkk = rawtkk.group(1)
            return

It worked for me. Thank you very much.

@isdaves
Copy link

isdaves commented Sep 20, 2018

>         r = self.session.get(self.host, verify=False)

This will cause InsecureRequestWarning warnings, no need for the "verify"

@Darkblader24
Copy link

>         r = self.session.get(self.host, verify=False)

This will cause InsecureRequestWarning warnings, no need for the "verify"

Oh, I forgot to remove this for this post.
I'm using this because some users had problems with their SSL which caused the request to fail. This prevents that. And I disable these InsecureRequestWarning by using:

requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)

isdaves pushed a commit to isdaves/py-meowbot that referenced this pull request Sep 21, 2018
@hrishikeshpatel
Copy link

@Darkblader24 after applying your solution i got below error..

380             obj, end = self.scan_once(s, idx)
381         except StopIteration:
382             raise ValueError("No JSON object could be decoded")
383         return obj, end

ValueError: No JSON object could be decoded

@Guy-Dipietro-Bose
Copy link
Author

@hrishikeshpatel that appears unrelated to these changes. I can't find that code block in the library.

@hrishikeshpatel
Copy link

But i got this type of error only after making these changes..
Please see detailed error if you can help

ValueError Traceback (most recent call last)
in ()
1 translator = Translator()
----> 2 t=translator.translate('hello', dest='hi')

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/client.pyc in translate(self, text, dest, src)
170
171 origin = text
--> 172 data = self._translate(text, dest, src)
173
174 # this code will be updated when the format is changed.

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/client.pyc in _translate(self, text, dest, src)
79 r = self.session.get(url, params=params)
80
---> 81 data = utils.format_json(r.text)
82 return data
83

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/utils.pyc in format_json(original)
60 converted = json.loads(original)
61 except ValueError:
---> 62 converted = legacy_format_json(original)
63
64 return converted

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/utils.pyc in legacy_format_json(original)
52 text = text[:p] + states[j][1] + text[nxt:]
53
---> 54 converted = json.loads(text)
55 return converted
56

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/json/init.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
337 parse_int is None and parse_float is None and
338 parse_constant is None and object_pairs_hook is None and not kw):
--> 339 return _default_decoder.decode(s)
340 if cls is None:
341 cls = JSONDecoder

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/json/decoder.pyc in decode(self, s, _w)
362
363 """
--> 364 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
365 end = _w(s, end).end()
366 if end != len(s):

/home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/json/decoder.pyc in raw_decode(self, s, idx)
380 obj, end = self.scan_once(s, idx)
381 except StopIteration:
--> 382 raise ValueError("No JSON object could be decoded")
383 return obj, end

ValueError: No JSON object could be decoded

@piotrglazar
Copy link

I can confirm that I have the same error as @hrishikeshpatel . It appeared after I applied @Darkblader24 's changes.

Fogapod added a commit to Fogapod/aiogoogletrans that referenced this pull request Sep 21, 2018
@programmerchad
Copy link

After applying @Darkblader24's fix, I'm also receiving the json error from googletrans/utils.py

@programmerchad
Copy link

programmerchad commented Sep 21, 2018

Here is r.text after using the fix listed here. Looks like its returning a 403:

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>403.</b> <ins>That’s an error.</ins>
  <p>Your client does not have permission to get URL <code>/translate_a/single?client=t&amp;sl=auto&amp;tl=en&amp;hl=en&amp;dt=at&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=qca&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t&amp;ie=UTF-8&amp;oe=UTF-8&amp;otf=1&amp;ssel=0&amp;tsel=0&amp;tk=684737.684737&amp;q=test</code> from this server.  <ins>That’s all we know.</ins>

@michalvaskovsky
Copy link

Yes. Same for me. Response 403 from google, Tried it at server that couldn't be banned.

@Darkblader24
Copy link

It works perfectly fine for me. Maybe this is somehow regional?

@piotrglazar
Copy link

piotrglazar commented Sep 22, 2018

I live in EU and I tried a VPN from USA to check if this regional. But I've encountered this in both cases. My script that uses this library is able to translate a couple of characters, but then it starts to fail with this JSON error. Is it possible that somehow it fails to renegotiate the token or something?

I get it now. You see the JSON error when you use google translate too much and it refuses to translate more. It tells you that there was too much traffic from your IP address an you should try again later. Do you have any way to bypass that?

@egyptianbman
Copy link

If it's restricting by ip, there's no way to bypass it other than cycle ips. Do you know what the limit is?

@piotrglazar
Copy link

I've saturated my IP address after about 14k characters.

@Guy-Dipietro-Bose
Copy link
Author

For those getting a 403, you'll see the same issue if you use curl (curl -A GET https://translate.google.com). There's most likely a limit being placed by Google when making multiple queries from the same IP. Keep in mind that the Google Translate API is a paid service now: https://cloud.google.com/translate/pricing

@stephwag
Copy link

stephwag commented Sep 23, 2018

Yeah, after applying this fix, it seems to work fine for me. I know that #47 is also related to getting a 403 when using certain emojis (which causes it to generate the wrong token). I applied this PR as a workaround and it seemed to fix that for me too. Not sure if that's the cause of the 403's people are getting here, but maybe it's worth looking into.

@LilianaNYC
Copy link

Here is another version of the fix, it is a bit cleaner:

    RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
                        re.DOTALL)
    RE_RAWTKK = re.compile(r'TKK=\'([^\']*)\';',re.DOTALL)

    def __init__(self, tkk='0', session=None, host='translate.google.com'):
        self.session = session or requests.Session()
        self.tkk = tkk
        self.host = host if 'http' in host else 'https://' + host

    def _update(self):
        """update tkk
        """
        # we don't need to update the base TKK value when it is still valid
        now = math.floor(int(time.time() * 1000) / 3600000.0)
        if self.tkk and int(self.tkk.split('.')[0]) == now:
            return

        r = self.session.get(self.host)

        rawtkk = self.RE_RAWTKK.search(r.text)
        if rawtkk:
            self.tkk = rawtkk.group(1)
            return

Edit: Removed verify=False from r = self.session.get(self.host, verify=False)

where canI find this file to make this change?

@stephwag stephwag mentioned this pull request Sep 25, 2018
andrvb added a commit to StepicOrg/py-googletrans that referenced this pull request Sep 26, 2018
@navid-ahrary
Copy link

Here is another version of the fix, it is a bit cleaner:

    RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
                        re.DOTALL)
    RE_RAWTKK = re.compile(r'TKK=\'([^\']*)\';',re.DOTALL)

    def __init__(self, tkk='0', session=None, host='translate.google.com'):
        self.session = session or requests.Session()
        self.tkk = tkk
        self.host = host if 'http' in host else 'https://' + host

    def _update(self):
        """update tkk
        """
        # we don't need to update the base TKK value when it is still valid
        now = math.floor(int(time.time() * 1000) / 3600000.0)
        if self.tkk and int(self.tkk.split('.')[0]) == now:
            return

        r = self.session.get(self.host)

        rawtkk = self.RE_RAWTKK.search(r.text)
        if rawtkk:
            self.tkk = rawtkk.group(1)
            return

Edit: Removed verify=False from r = self.session.get(self.host, verify=False)

work for me too . tnx

@speaktech-account
Copy link

@asanchez126
I encountered the same problem.

    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

It can be reproduced on my environment when original text to be translated has more than 5,000 characters. I don`t know why it happens, but I solved this problem by separating every 5,000 characters and translating each of them.

@AndriiOmelianenko
Copy link

hey folks, any updates on when this is going to be merged?

@Guy-Dipietro-Bose
Copy link
Author

Haven't heard from the repo owner, not sure that it will get merged. I've been using the fork, we may need to completely fork it and publish to Pypi.

@majkrzak
Copy link

@Guy-Dipietro-Bose please consider claiming ownership on pipy

@mikklaos
Copy link

@Guy-Dipietro-Bose please make a fork :)

@rahiel
Copy link

rahiel commented Oct 11, 2018

Until this is released, you can also install the code of this PR over git:

pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade

@astariul
Copy link

I am using time delay between queries and it works for me

@loopdigga98 How much delay did you put between each query ?

My IP is blocked by Google. How can I unblock it ?

@piotrglazar
Copy link

The only thing to do is wait. You should be able to use it after ca. 24 hours. I'm using 1 second delay between queries and it works for me.

@umairqadir97
Copy link

uninstall already installed googletrans package
pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade
and you are done !

much easier solution !

@boing102
Copy link

boing102 commented Nov 1, 2018

@umairqadir97 Did that work for you? I've tried that earlier today and got
in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@umairqadir97
Copy link

umairqadir97 commented Nov 2, 2018

@umairqadir97 Did that work for you? I've tried that earlier today and got
in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@boing102 yes it's working for me. This is something i'm trying with it:

translator = Translator()
translator.detect("string to be detected").lang

@boing102
Copy link

boing102 commented Nov 2, 2018

@umairqadir97 Did that work for you? I've tried that earlier today and got
in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@boing102 yes it's working for me. This is something i'm trying with it:

translator = Translator()
translator.detect("string to be detected").lang

I've tried both detect() and translate() functions, both yielding the same error. Also in the brand new venv, guess I just have to wait.

@umairqadir97
Copy link

@umairqadir97 Did that work for you? I've tried that earlier today and got
in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@boing102 yes it's working for me. This is something i'm trying with it:

translator = Translator()
translator.detect("string to be detected").lang

I've tried both detect() and translate() functions, both yielding the same error. Also in the brand new venv, guess I just have to wait.

@boing102 Have you installed it from above mentioned git Repo? Can you sendyour snippet plus error it's showing ?

@boing102
Copy link

boing102 commented Nov 2, 2018

@umairqadir97 Yep, I used that repo to install.
Here is the stacktrace:
>>> translator.detect("string to be detected").lang Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/tmp/py_venv/try/lib/python3.6/site-packages/googletrans/client.py", line 249, in detect data = self._translate(text, dest='en', src='auto') File "/tmp/py_venv/try/lib/python3.6/site-packages/googletrans/client.py", line 81, in _translate data = utils.format_json(r.text) File "/tmp/py_venv/try/lib/python3.6/site-packages/googletrans/utils.py", line 62, in format_json converted = legacy_format_json(original) File "/tmp/py_venv/try/lib/python3.6/site-packages/googletrans/utils.py", line 54, in legacy_format_json converted = json.loads(text) File "/usr/lib/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@tgi01054
Copy link

tgi01054 commented Nov 5, 2018

In my opinion, Google may block web api that py-googletrans uses.
Using debug logging level, I found http web API. That API responsed 503.

In detail, I made a curl call for that url. Response was that google blocks invalid request.

Although I have figured out the cause, but there is no solution.
I looking for free translate API in Python.
I hope that this issue will be resolved.

= Logging for py-googletrans

$ python
Python 3.5.1 (default, Apr  7 2018, 08:31:07)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import http.client as http_client
>>> http_client.HTTPConnection.debuglevel = 1
>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate('안녕하세요.')
send: b'GET / HTTP/1.1\r\nHost: translate.google.com\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date header: Expires header: Cache-Control header: Pragma header: X-Frame-Options header: Content-Type header: Content-Language header: P3P header: X-Content-Type-Options header: Content-Encoding header: Server header: X-XSS-Protection header: Set-Cookie header: Alt-Svc header: Transfer-Encoding send: b'GET /translate_a/single?q=%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94.&hl=en&tl=en&sl=auto&otf=1&ssel=0&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&client=t&tk=9673.437582&oe=UTF-8&ie=UTF-8&tsel=0 HTTP/1.1\r\nHost: translate.google.com\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nCookie: NID=144=oQwUK0rMolJ4wc4g8u-w_Uw_iSl5Nm1wg69-SmsZ8RPW9kM3T72Tpf714EvxNuwI-5Q9VVCGoh0DmNoGr4tj-1vrIIKOXCROTJuAVeh249mFHr1FNZyR6QNfvSLtLtKGfUq7QfGk9YYmPKVvDisz13GwjXPps4j-iSJp3ehzJ-E\r\n\r\n'
reply: 'HTTP/1.1 503 Service Unavailable\r\n'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wskim/apps/pic_crawing_1/venv/lib/python3.5/site-packages/googletrans/client.py", line 172, in translate
    data = self._translate(text, dest, src)
  File "/home/wskim/apps/pic_crawing_1/venv/lib/python3.5/site-packages/googletrans/client.py", line 81, in _translate
    data = utils.format_json(r.text)
  File "/home/wskim/apps/pic_crawing_1/venv/lib/python3.5/site-packages/googletrans/utils.py", line 62, in format_json
    converted = legacy_format_json(original)
  File "/home/wskim/apps/pic_crawing_1/venv/lib/python3.5/site-packages/googletrans/utils.py", line 54, in legacy_format_json
    converted = json.loads(text)
  File "/usr/local/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
header: Date header: Pragma header: Expires header: Cache-Control header: Content-Type header: Server header: Content-Length header: X-XSS-Protection header: Alt-Svc 
>>>

= Curl call

$ curl -v 'https://translate.google.com:443/translate_a/single?q=%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94.&hl=en&tl=en&sl=auto&otf=1&ssel=0&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&client=t&tk=9673.437582&oe=UTF-8&ie=UTF-8&tsel=0'
* About to connect() to translate.google.com port 443 (#0)
*   Trying 172.217.31.238... connected
* Connected to translate.google.com (172.217.31.238) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* 	subject: CN=*.google.com,O=Google LLC,L=Mountain View,ST=California,C=US
* 	start date: Oct 16 11:37:00 2018 GMT
* 	expire date: Jan 08 11:37:00 2019 GMT
* 	common name: *.google.com
* 	issuer: CN=Google Internet Authority G3,O=Google Trust Services,C=US
> GET /translate_a/single?q=%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94.&hl=en&tl=en&sl=auto&otf=1&ssel=0&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&client=t&tk=9673.437582&oe=UTF-8&ie=UTF-8&tsel=0 HTTP/1.1
> User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: translate.google.com
> Accept: */*
>
< HTTP/1.1 503 Service Unavailable
< Date: Mon, 05 Nov 2018 08:01:24 GMT
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Content-Type: text/html
< Server: HTTP server (unknown)
< Content-Length: 2341
< X-XSS-Protection: 1; mode=block
< Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35"
<
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1"><title>https://translate.google.com/translate_a/single?q=%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94.&amp;hl=en&amp;tl=en&amp;sl=auto&amp;otf=1&amp;ssel=0&amp;dt=at&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=qca&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t&amp;client=t&amp;tk=9673.437582&amp;oe=UTF-8&amp;ie=UTF-8&amp;tsel=0</title></head>
<body style="font-family: arial, sans-serif; background-color: #fff; color: #000; padding:20px; font-size:18px;" onload="e=document.getElementById('captcha');if(e){e.focus();}">
<div style="max-width:400px;">
<hr noshade size="1" style="color:#ccc; background-color:#ccc;"><br>
<div style="font-size:13px;">
Our systems have detected unusual traffic from your computer network.  Please try your request again later.  <a href="#" onclick="document.getElementById('infoDiv0').style.display='block';">Why did this happen?</a><br><br>
<div id="infoDiv0" style="display:none; background-color:#eee; padding:10px; margin:0 0 15px 0; line-height:1.4em;">
This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the <a href="//www.google.com/policies/terms/">Terms of Service</a>. The block will expire shortly after those requests stop.<br><br>This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests.  If you share your network connection, ask your administrator for help &mdash; a different computer using the same IP address may be responsible.  <a href="//support.google.com/websearch/answer/86640">Learn more</a><br><br>Sometimes you may see this page if you are using advanced terms that robots are known to use, or sending requests very quickly.
</div><br>

IP address: 115.68.232.37<br>Time: 2018-11-05T08:01:24Z<br>URL: https://translate.google.com/translate_a/single?q=%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94.&amp;hl=en&amp;tl=en&amp;sl=auto&amp;otf=1&amp;ssel=0&amp;dt=at&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=qca&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t&amp;client=t&amp;tk=9673.437582&amp;oe=UTF-8&amp;ie=UTF-8&amp;tsel=0<br>
</div>
</div>
</body>
</html>
* Connection #0 to host translate.google.com left intact
* Closing connection #0
$

@boing102
Copy link

boing102 commented Nov 5, 2018

@tgi01054 Goslate is working for me at the time of writing.

EDIT:
I've also find this Yandex Translate API. Not as good as google, but it is free for 1M chars per day.

@ifiodara
Copy link

ifiodara commented Nov 29, 2018

Worked for me

Request returnes new format of tkk field in response page

RE_TKK = re.compile(r'tkk:\'(.+?)\'')      
  
    def __init__(self, tkk='0', session=None, host='translate.google.com'):
        self.session = session or requests.Session()
        self.tkk = tkk
        self.host = host if 'http' in host else 'https://' + host

    def _update(self):
        """update tkk
        """
        # we don't need to update the base TKK value when it is still valid
        r = self.session.get(self.host)        
        
        self.tkk = self.RE_TKK.findall(r.text)[0]
        
        now = math.floor(int(time.time() * 1000) / 3600000.0)
        if self.tkk and int(self.tkk.split('.')[0]) == now:
            return

        # this will be the same as python code after stripping out a reserved word 'var'
        code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
        # unescape special ascii characters such like a \x3d(=)

@ssut
Copy link
Owner

ssut commented Dec 19, 2018

I close this pull request now that I have merged #95.

@1998Suraj
Copy link

I try to make a translator and this error comes.
please give me a solution.
thankyou
##############################################
exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Mowgli\anaconda3\lib\tkinter_init_.py", line 1883, in call
return self.func(*args)
File "", line 12, in trans
speech=trans.txt
AttributeError: 'Translated' object has no attribute 'txt'

@ssut
Copy link
Owner

ssut commented Oct 15, 2020

@1998Suraj I suspect you made a typo: speech=trans.text.

Repository owner locked as resolved and limited conversation to collaborators Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet