Quick fix tip “googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’”

Many users using google trans in Java ask for help because they encountered an error during implementation.

These users asked that while using Java and doing google trans, they encountered the error “googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’“. To not waste your time, the answer to the problem is right here!

How Is The “”googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’”” Error Shown?

When using google trans in Java, many people get display errors with content related to “AttributeError”, “‘NoneType’”, and “no group attribute”. This error will be most fully displayed as follows:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    translator.translate('Hola como estas ?')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/client.py", line 172, in translate
    data = self._translate(text, dest, src)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/client.py", line 75, in _translate
    token = self.token_acquirer.do(text)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/gtoken.py", line 180, in do
    self._update()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/gtoken.py", line 59, in _update
    code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

What Is The Solution To This Error?

Many users are doing google trans and encounter display errors related to issues like “AttributeError”, “‘NoneType’”, and “no group attribute”. This error is displayed to report the error of installing the latest version of google trans.

On the other hand, this error also indicates that version pip installs google trans==4.0.0-rc1. Right now, you can use google translate. 

Solution 1 – Install The Newest Google Translate Version

Please install the latest version of google trans to fix this error. Furthermore, you can use this version to install:

pip install googletrans==4.0.0-rc1

After this process, you can freely operate google translate.

translator = Translator()
translation = translator.translate("Hola como estas ?", dest='en')
print(translation.text)
#output: 'Hello How are you ?'

Solution 2 – Use “Google-Trans-New”

With this second method, you can use “google_trans_new” with the following statement:

pip install google_trans_new

Check out this easy example:

from google_trans_new import google_translator  
  
translator = google_translator()  
translate_text = translator.translate('Hola mundo!', lang_src='es', lang_tgt='en')  
print(translate_text)

-> Hello world!

Solution 3 – Operate This Command

You can execute the following command:

pip uninstall googletrans
git clone https://github.com/alainrouillon/py-googletrans.git
cd ./py-googletrans
git checkout origin/feature/enhance-use-of-direct-api
python setup.py install

Conclusion

Hopefully, following the above helpful tips will help you fix the “googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’” error as quickly as possible. If you have any questions or difficulties, please ask us through the comments below!


Related articles

Scroll to Top