py-googletrans: [Error] Google changed their API... again

Google has changed their API yet again. Using this tool and the fix in #78 no longer works as it now gives this error:

\googletrans\gtoken.py", line 66, in _update code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '') AttributeError: 'NoneType' object has no attribute 'group'

Does anybody have an idea how to fix this?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 22

Commits related to this issue

Most upvoted comments

My husband got mine to work by doing this to gtoken.py:

Change

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

to

RE_TKK = re.compile(r'tkk:\'(.+?)\'', re.DOTALL)
RE_RAWTKK = re.compile(r'tkk:\'(.+?)\'', re.DOTALL)

Though he isn’t really sure of the differences between RAWTKK and TKK, but this was just a really quick fix that he implemented.

Using advices/comments from yasirtug and the code of hnljq, a notebook using lorem (french -> english) and with non-ascii chars => https://gist.github.com/yoyonel/78081a1466121617ff27c307a79b82cd#file-google_translate-ipynb

@Guy-Dipietro-Bose you’re my hero ! 😄 Unit tests work fine now ! Thx again !

@hnljq couldn’t know what kind of answer do you exactly want and i will repeat a little, sorry for that. with this method, we get the result by using google’s own way, which is to ask with a secret token and get the result with some extra details like ‘confidence’ directly. with your code, we literally download this page to translate ‘hello’ to chinese from english, and then parse the downloaded page to take the result ’ 你好 '. out of topic but i just realised that your code is also not enough to work with queries which include non ascii characters. this can be solved though, by using percent-encoding.