py-googletrans: Announcement: Temporary Fix For (AttributeError: 'NoneType' object has no attribute 'group') in 3.0.0 Version

For anyone receives NoneType' object has no attribute 'group, if you are currently using googletrans==3.0.0, please switch to googletrans==3.1.0a0 for the temporary fix.

Related Issue: #234

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 59
  • Comments: 56 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Hi folks! Now I’m rewriting the entire codebase of this project in order to deal with rate-limiting, focusing on better stability, and reliability. This work can take some time but I’ll try to complete it asap, so please be patient, and note that you all have to use the official Google Cloud Translate API for production purposes even if fixes come out. Thank you all supporting this project, I’ll bring back good news soon.

I have a problem with this version. The text is not translated and the translate function returns the original text. Example:

>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate(text='küche', dest='en')
Translated(src=en, dest=en, text=küche, pronunciation=küche, extra_data="{'translat...")
>>> translator.translate(text='küche', dest='en', src='de')
Translated(src=en, dest=en, text=küche, pronunciation=küche, extra_data="{'translat...")

I would expect kitchen as the correct translation. Is this a bug or am I doing sometimes wrong here?

For anyone receives NoneType' object has no attribute 'group, if you are currently using googletrans==3.0.0, please switch to googletrans==3.1.0a0 for the temporary fix.

Related Issue: #234

Hi guys This problem has been solved in new version. please install 4.0.0rc1 version pip install googletrans==4.0.0rc1

The issue still in googletrans==3.1.0a0

Traceback (most recent call last):
  File "/home/freax/work/python/myfreax/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 63, in _update
    code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    tranlated = translator.translate('안녕하세요.', dest='ja')
  File "/home/freax/work/python/myfreax/venv/lib/python3.8/site-packages/googletrans/client.py", line 210, in translate
    data, response = self._translate(text, dest, src, kwargs)
  File "/home/freax/work/python/myfreax/venv/lib/python3.8/site-packages/googletrans/client.py", line 102, in _translate
    token = self.token_acquirer.do(text)
  File "/home/freax/work/python/myfreax/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 199, in do
    self._update()
  File "/home/freax/work/python/myfreax/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 67, in _update
    raise Exception('Could not find TKK token for this request.\nSee https://github.com/ssut/py-googletrans/issues/234 for more details.')
Exception: Could not find TKK token for this request.
See https://github.com/ssut/py-googletrans/issues/234 for more details.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
(venv) ➜  myfreax git:(master) ✗ python --version
Python 3.8.5
from googletrans import Translator
translator = Translator(service_urls=[
      'translate.google.cn',
    ])
tranlated = translator.translate('hello.', dest='zh-CN')
print(tranlated)

I can provide more information

On Mac with macOS Big Sur the same: neither 3.1.0a0 nor 4.0.0rc1 works

googletrans==3.1.0a0 at python version 3.8.5 doesn’t work for me.

Mine is working now

from googletrans import Translator translator = Translator() tranlated = translator.translate(‘hello.’, dest=‘igbo’) print(tranlated.text)

Nnọọ.

Same error, neither version 3.1.0a0 nor 4.0.0rc1 works.

Hey all, just jump up to the 4.0.0rc1 release it works.

Sorry. I’m in error environment test. Now try again test and install googletrans==3.1.0a0. It’s work well. But below the code can’t wrok

from googletrans import Translator
translator = Translator(service_urls=[
      'translate.google.cn',
    ])
tranlated = translator.translate('hello.', dest='zh-CN')
print(tranlated)

For a quick fix try:-

(22-sep-2021)

googletrans==3.1.0a0

It works for me 👍

If I use the default settings the translations work for a few requests, then translator returns the same string I submitted. If I try to specify the service URL I get the error:

AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/pytorch/lib/python3.7/site-packages/googletrans/gtoken.py in _update(self)
     62             # this will be the same as python code after stripping out a reserved word 'var'
---> 63             code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
     64             # unescape special ascii characters such like a \x3d(=)

AttributeError: 'NoneType' object has no attribute 'group'

Either way, it doesn’t work.

Edit: I am using googletrans==3.1.0a0

This worked for me with googletrans==3.1.0a0 at Ubuntu 20.04.5 LTS.

pip3 uninstall googletrans sudo pip3 uninstall googletrans

PD: some times first install without sudo fails and I retry then with sudo.

Thx!

For a quick fix try:-

(22-sep-2021)

googletrans==3.1.0a0

It works for me 👍

The following worked for me on pyThon 3.8.5 on Windows10.

  • pip install googletrans==3.1.0a0
  • reboot
  • In IDE environment
  • import googletrans
  • from googletrans import Translator
  • translator = Translator()
  • tranlated = translator.translate(‘hello.’, dest=‘zh-CN’)
  • print(tranlated)

For those who want to install 4.0.0rc1, you can use this command:

python -m pip install --pre googletrans

For anyone receives NoneType' object has no attribute 'group, if you are currently using googletrans==3.0.0, please switch to googletrans==3.1.0a0 for the temporary fix. Related Issue: #234

Hi guys This problem has been solved in new version. please install 4.0.0rc1 version pip install googletrans==4.0.0rc1

Does it work with emojis? like 😀 in the text?

Sorry for interrupting but I have a question. I don’t know a better place to ask this kind of question. Speech audio is currently not supported, is it? You know, if you go to Google Translate, and type something there is a speaker button that reads the text. I looked at the Network communication, and speech seems to be calling https://translate.google.com/_/TranslateWebserverUi/data/batchexecute? and the response seems to contain some base64-looking encoded data, which is probably the audio data.

While I look forward to the rewrite, I just got it working. My mistake was embarrassing! I didn’t have wheel installed in my venv, so the install of this package failed. Just sharing in case others are stuck and getting the same issue.

Originally got the “NoneType not iterable” problem. After pip3 install wheel, pip3 uninstall googletrans, pip3 install googletrans, this changed to “NoneType has not attribute group”. After pip3 install googletrans==3.1.0a0 it worked.

Thanks for your work people 🙏

Sorry. I’m in error environment test. Now try again test and install googletrans==3.1.0a0. It’s work well. But below the code can’t wrok

from googletrans import Translator
translator = Translator(service_urls=[
      'translate.google.cn',
    ])
tranlated = translator.translate('hello.', dest='zh-CN')
print(tranlated)

Yes, that’s what I was saying 😃

Hi @terryyz Thanks for your follow-up. I don’t have access to my home laptop at the moment, but I tested it on another machine, and indeed it is working fine now. Sorry about the false alarm. Thanks again for your support.