atykhonov / google-translate

Emacs interface to Google Translate
370 stars 47 forks source link

Failed to search TKK #52

Open renatofdds opened 8 years ago

renatofdds commented 8 years ago

Any translation attempt is failing with the error: google-translate--search-tkk: Failed to search TKK

atykhonov commented 8 years ago

Hi @renatofdds,

which version do you use? M-x google-translate-version RET.

ardangelo commented 8 years ago

I'm also having this problem. Using most recent version 0.11.11

renatofdds commented 8 years ago

I'm also on 0.11.11

jack836 commented 8 years ago

Facing the same issue on 0.11.11. Any help is highly appreciated, BTW, I am behind a http proxy.

atykhonov commented 8 years ago

Hi all!

I have no idea what exactly could be the root cause of the issue. But with your help I believe the reason could be discovered and the issue fixed.

I've just pushed the code (0.11.12 version) which should help us to debug the issues which relate to retrieving of TKK.

With these changes, please, execute M-: (setq google-translate--tkk-debug t) RET (or M-x eval-expression RET (setq google-translate--tkk-debug t) RET). Then try to translate a word/sentence as usually you do. As the result, two buffers should appear. First one usual one (*Google Translate*) with the translation, and the second one (*Google Translate Debug*) with the debug info, i.e. HTML which is used for retrieving of TKK. Then please paste the contents of *Google Translate Debug* buffer here.

atykhonov commented 8 years ago

If you'll see that someone already posted the similar output as you get, please feel free to post it again, or just notify that you get the same output. I just believe that additional information would be helpful.

Actually any help is highly appreciated!

Thank you in advance!

jack836 commented 8 years ago

Thank you for the efforts and further steps. I will report the test results soon.

jack836 commented 8 years ago

After upgrading to 0.11.12 and setting the debug to true as you suggested I did a google-translate-smooth-translate.

I don't see two windows open and I receive the same error. This is what happens

Translate : "The text to be translated appears here correctly (Japanese)" RET Translate from : Japanese RET Translate to : English RET connecting to proxy.xxx.xxx.xx Failed to Search TKK

But version 0.11.10 works perfectly at my home computer (11.11 and 11.12 not tested yet). The above test was from my office computer and the only difference is that, the office computer is behind a http proxy. So I strongly doubt it has something to do with proxy.

Further testing for connection through proxy

  1. 'wget' from terminal connects successfully to http and https 2.'eww' from emacs connects to http but fails to establish a connection to https
  2. 'package-list-packages' from emacs downloads successfully from http sources (melpa and org) but fails to download from https source (marmalade)

Since google translate has to establish a connection to https://translate.google.com, i strongly suspect it has something to do with my proxy setting. Sorry if I wasted your time.

But I would sincerely appreciate if you can point out some ways I can make it to work in my work-computer behind proxy. I also hope many people need google translate in their office computer which is normally behind a proxy.

Thank you for your time and efforts

rfkm commented 7 years ago

Interesting. My case is opposite. While it works on my office computer, doesn't work on my home computer. Both uses same emacs settings including google-translate's versions(0.11.13).

EDITED:

jack836 commented 7 years ago

SOLVED The issue was Emacs-25.0 was using the "GET method" to connect to HTTPS sites, which my company's firewall (proxy) didn't like. The solution is to make Emacs use the "CONNECT method" to request connection to HTTPS sites (which the proxy allows). The following page correctly directed me towards the solution.

http://emacs.1067599.n8.nabble.com/bug-11788-url-http-does-not-properly-handle-https-over-proxy-td46070.html

Either modify that one particular .el file and rebuild you emacs OR update to 'emacs-snapshot' version-26. I took the easier step and updated to Emacs-26.0.50.2. Now google-translate works like a charm within emacs. Thank you all for the pointers and support

rfkm commented 7 years ago

@jack836 Good news. Thank you for sharing. BTW, I've edited my comment since it was wrong. My home network doesn't use a proxy AFAIK, but it seems worthwhile to try that. Again, thanks!

ikedaisuke commented 7 years ago

When I updated Emacs 25.1 to Emacs 25.2, I found the issue.

The issue is solved on my PC when google-translate package turns to request through HTTPS but not HTTP by setting google-translate-base-url and google-translate--tkk-url as follows

  (when (and (= emacs-major-version 25) (<= emacs-minor-version 2))
    (setq google-translate-base-url
          "https://translate.google.com/translate_a/single"
          google-translate--tkk-url
          "https://translate.google.com/"))

I am uncertain about the issue at Emacs 25.1 @jack836 mentions above that the problem is solved at Emacs 26 https://github.com/atykhonov/google-translate/issues/52#issuecomment-265949189

Wish it will be helpful.

Info:

Emacs version "25.2.1" which is built with GnuTLS library
(google-translate-version) says "Google Translate (version): 0.11.14"
google-translate package is installed via MELPA version 20170713.119; not MELPA stable
crystle9 commented 6 years ago

I met the same problem. After configuring a socks5 proxy for emacs, the problem got addressed. Maybe it's concerning to the ISP, who blocks the network traffic to google services. However, I found something weired. With network proxy set globally in gnome 3, the google services can be visited by firefox browser, but they are not available in eww web browser in emacs. The socks5 proxy settings in gnome 3 seems to be ignored.

example socks5 proxy for emacs:

(setq url-gateway-method 'socks)
(setq socks-server '("Default server" "127.0.0.1" 1080 5))
sshaw commented 6 years ago

This just started happening to me after months without a problem. But, it went away after a few minutes. I am not using a proxy.

UPDATE: Now using a different computer that also worked without a problem. It's now failing with the same message. ๐Ÿ’ป๐Ÿ”จ

rantonse commented 6 years ago

Same problem here. It has been working for months without a problem, but now i get google-translate--search-tkk: Failed to search TKK all the time. I tried to set google-translate--tkk-debug to true, but no second buffer with debug info appears.

touxstone commented 6 years ago

Same problem here. It has been working for months without a problem, but now i get google-translate--search-tkk: Failed to search TKK all the time. I tried to set google-translate--tkk-debug to true, but no second buffer with debug info appears.

same issue here /'' (;;Emacs version 25.3; google-translate version 0.11.14)

aanoaa commented 6 years ago

same here

GNU Emacs 26.1
Google Translate (version): 0.11.14
rantonse commented 6 years ago

The problem seems to be that the google-translate--tkk-regex definition in google-translate-tk.el,

https://github.com/atykhonov/google-translate/blob/d8b84a8359fcc697114d1298840e9a45b111c974/google-translate-tk.el#L50

does not match the appropriate string in the retrieved HTML document, which in my case was

TKK='427110.1469889687'.

I'm also running Emacs 26.1 and version 0.11.14.

atykhonov commented 6 years ago

same here, I'm investigating and looking for a solution

atykhonov commented 6 years ago

does not match the appropriate string in the retrieved HTML document

yes, previously HTML had something like the following:

TKK=eval('((function(){var a\x3d3470396290;var b\x3d183821724;return 426874+\x27.\x27+(a+b)})())');

now we have this representation: TKK='427116.3269864724';.

SunDawning commented 6 years ago

@atykhonov @rantonse

I found a quick fix. Try it:

(when (and (string-match "0.11.14"
                         (google-translate-version))
           (>= (time-to-seconds)
               (time-to-seconds
                (encode-time 0 0 0 23 9 2018))))
  (defun google-translate--get-b-d1 ()
    ;; TKK='427110.1469889687'
    (list 427110 1469889687)))

You can use TKK='427110.1469889687', TKK='427116.3269864724' or other value.

0--key commented 6 years ago

Same problem here. It has been working for months without a problem, but now i get google-translate--search-tkk: Failed to search TKK all the time. I tried to set google-translate--tkk-debug to true, but no second buffer with debug info appears.

Emacs 25.1.1; Google Translate (version): 0.11.14

A stubborn error in the Messages buffer:

 google-translate--search-tkk: Failed to search TKK

even if I change:

    (setq google-translate-base-url                                                                                            
          "https://translate.google.com/translate_a/single"                                                                    
          google-translate--tkk-url                                                                                            
          "https://translate.google.com/") 
jajpater commented 6 years ago

Same here.

edurante commented 6 years ago

I had the same problems two days ago. My emacs version is 26.1

@SunDawning your fix work for me. Thanks you

(use-package google-translate
:ensure t
:config
(when (and (string-match "0.11.14"
(google-translate-version))
             (>= (time-to-seconds)
         (time-to-seconds
                  (encode-time 0 0 0 23 9 2018))))
    (defun google-translate--get-b-d1 ()
      ;; TKK='427110.1469889687'
      (list 427110 1469889687))))
ybiquitous commented 6 years ago

@edurante Thanks for your workaround!

I also use use-package, and the below patch works for me. ๐Ÿ˜ƒ

-:config
+:init
ybiquitous commented 6 years ago

I'm very sorry! The above patch in https://github.com/atykhonov/google-translate/issues/52#issuecomment-424796072 is my misunderstanding. ๐Ÿ™‡ (:config is correct, NOT :init)

Also, I need this workaround using bind-keys* instead of :bind:

(use-package google-translate
  :config
  ;; ...
  ;; Workaround in https://github.com/atykhonov/google-translate/issues/52#issuecomment-424302439
  ;; ...

  ;; BEGIN: Workaround which I need
  (bind-keys*
    ("C-c t" . google-translate-at-point)
    ("C-c T" . google-translate-at-point-reverse))
  ;; :bind (("C-c t" . google-translate-at-point)
  ;;        ("C-c T" . google-translate-at-point-reverse))
  ;; END
  )
atykhonov commented 6 years ago

@SunDawning it works very well! Thanks a lot! I'm preparing a patch based on the workaround.

atykhonov commented 6 years ago

The v0.11.15 have been released with the fix. Please update. It works well. In a case of any issue please report here (the issue is not going to be closed while we have tkk).

All credit to @SunDawning.

Thank you all!

jack836 commented 6 years ago

The latest version works fine (no TKK error any more). I needed to restart emacs after re-installing google-translate.

some-mthfka commented 6 years ago

Looks like the error is up again Search failed: ";TKK='", could someone, please, confirm? All worked just about a week ago.

Version: 0.11.15.

some-mthfka commented 6 years ago

I am glad to say that everything got back to normal a couple of days ago. Only makes me wonder what could've have been the issue for more than a week, considering I didn't change anything systemwise on my computer.

atykhonov commented 6 years ago

@grigorievich it happens sometimes (quite rare) to me. I just translate again and get successful translation immediately after the issue.

some-mthfka commented 6 years ago

@atykhonov I see what you mean. I did give it multiple consequtive tries on different days. Well, I sure am glad to see it working again!

atykhonov commented 5 years ago

@grigorievich me too. Thanks for the report nevertheless, this might be not so harmless as it looks like, so I'm keeping watch over it.

yuya373 commented 5 years ago

I got same error.

diff --git a/google-translate-tk.el b/google-translate-tk.el
index 4af9b87..2bac471 100644
--- a/google-translate-tk.el
+++ b/google-translate-tk.el
@@ -137,6 +137,8 @@ D is an integer."
   (let* ((url-request-extra-headers '(("Connection" . "close")))
          (buf (url-retrieve-synchronously google-translate--tkk-url)))
     (with-current-buffer buf
+      (message "%S" (buffer-substring-no-properties (point-min)
+                                                    (point-max)))
       (google-translate--search-tkk))))

 (defun google-translate--gen-rl (a b)

with above debug code, I got following output. (extract tkk related)

var mobileWebapp={display_language: // snip...
campaign_tracker_id:'1h',tkk:'428741.3398103640',  // snip...
false,enable_auto_update_result:false};var messages // snip...
TKK = mobileWebapp.tkk;

fix google-translate--search-tkk like below, then the error seems fixed.

diff --git a/google-translate-tk.el b/google-translate-tk.el
index 4af9b87..e7a7c2f 100644
--- a/google-translate-tk.el
+++ b/google-translate-tk.el
@@ -124,8 +124,8 @@ D is an integer."
   (let ((start nil)
         (tkk nil)
         (nums '()))
-    (setq start (search-forward ";TKK='"))
-    (search-forward "';")
+    (setq start (search-forward ",tkk:'"))
+    (search-forward "',")
     (backward-char 2)
     (setq tkk (buffer-substring start (point)))
     (setq nums (split-string tkk "\\."))
ybiquitous commented 5 years ago

@yuya373 Your patch works fine. Thanks a lot! ๐Ÿ˜†

alexander31415926535 commented 5 years ago

Yes! @yuya373 patch works great! Emacs 25.1, newest version of google-translate from melpa.

atykhonov commented 5 years ago

It looks like that an issue that happens quite rare, turned into a permanent issue. It is fixed in 0.11.16 version. google-translate doesn't work for me without the mentioned patch. @yuya373 thanks a lot!

jmburgos commented 5 years ago

I am having this issue, using version 0.11.17 and emacs 26.1.

touxstone commented 5 years ago

Looks like the error is up again, :disappointed: The output I got reads: Search failed: ",tkk:'" I'm using google-translate, version 0.11.17 and emacs 26.1

a7f4 commented 5 years ago

(url-retrieve-synchronously google-translate--tkk-url) this one sometimes returns an empty string, so searching TKK will fail @touxstone, as a temporary solution you can try to replace 'google-translate--search-tkk' by:

(defun google-translate--search-tkk () "Search TKK." (list 430675 2721866130))

But I guess there should be some kind of cache... @atykhonov what do you think?

touxstone commented 5 years ago

Hi, @a7f4 thanks though (replaced as suggested and restarted Emacs) it doesn't work for me (same output).

a7f4 commented 5 years ago

@touxstone I guess you have at least one more version of this package.

try this one:

find ~/.emacs.d -name "google-translate-tk.el"

I suppose that you'll get more than one )

touxstone commented 5 years ago

I guess you have at least one more version of this package.

try this one:

find ~/.emacs.d -name "google-translate-tk.el"

I suppose that you'll get more than one )

so, the output I got is:

.emacs.d/elpa/google-translate-20190206.1229/google-translate-tk.el
a7f4 commented 5 years ago

@touxstone It's quite strange if you've replaced the original google-translate--search-tkk you should not be able to get the same output: Search failed: ",tkk:'" maybe you have emacs --daemon running on your machine?

anyway, make sure that: 1) google-translate-tk.el contains only one definition of google-translate--search-tkk and this definition exactly : (defun google-translate--search-tkk () "Search TKK." (list 430675 2721866130)) 2) and you have only one fresh running instance of emacs

touxstone commented 5 years ago

I am also puzzled. I've tried all the checkings I've been able to. replaced the above-given function, Mx-kill-emacs, restated the PC (even) included and same output...

rileyrg commented 5 years ago

emacs 26.1 on debian buster.

google-translate--search-tkk: Search failed: ",tkk:'"

google-translate-buffer is an interactive autoloaded compiled Lisp function in โ€˜.emacs.d/elpa/google-translate-20190206.1229/google-translate-default-ui.elโ€™.

cerkut commented 5 years ago

(defun google-translate--search-tkk () "Search TKK." (list 430675 2721866130)) works for me and stops the error

google-translate--search-tkk: Search failed: ",tkk:'"

D00mch commented 5 years ago

(defun google-translate--search-tkk () "Search TKK." (list 430675 2721866130)) This works, but for only one translation. If I translate something, then close the window with the translation, and then try to translate again, I get the same error:

"Search failed: ",tkk" I need to restart emacs to be able to translate again.

So I temporarily solved it with translate-shell. It's working like this: I open "shell-command" and type "e word-to-translate", and have a result. For this to work:

  1. I added aliases to translate from/to interested langs:
    alias ั€='trans -b ru:en'
    alias e='trans en:ru -brief'
    alias eng='trans en:ru'
  2. And I added (setq shell-command-switch "-ic") to my .spacemacs dotspacemacs/user-config to support loading .bashrc for "shell-command".
a7f4 commented 5 years ago

@Liverm0r :

(defun google-translate--search-tkk () "Search TKK." (list 430675 2721866130)) This works, but for only one translation. If I translate something, then close the window with the translation, and then try to translate again, I get the same error:

"Search failed: ",tkk" I need to restart emacs to be able to translate again.

It causes because you didn't override the original function, but defined a function with the same name so, at first execution, it works but then original function overrides your definition.

try to find google-translate-tk.el and replace google-translate--search-tkk within it But pls note! this is also a temporary solution

you can find my trying for resolve this issue here: #85