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

Announcement: Temporary Fix For (AttributeError: 'NoneType' object has no attribute 'group') in 3.0.0 Version #280

Open
terryyz opened this issue Mar 10, 2021 · 57 comments
Labels

Comments

@terryyz
Copy link
Collaborator

terryyz commented Mar 10, 2021

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

@terryyz terryyz added the pinned label Mar 10, 2021
@terryyz terryyz pinned this issue Mar 10, 2021
@terryyz terryyz changed the title Temporary Fix For (AttributeError: 'NoneType' object has no attribute 'group') in 3.0.0 Version Announcement: Temporary Fix For (AttributeError: 'NoneType' object has no attribute 'group') in 3.0.0 Version Mar 10, 2021
@mzeidhassan
Copy link

I am still having the same issue after installing googletrans==3.1.0a0

AttributeError                            Traceback (most recent call last)
<ipython-input-26-7d02fc64043f> in <module>
      1 from googletrans import Translator
      2 translator = Translator()
----> 3 print(translator.translate('أحبك', src='ar', dest= 'en'))

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\client.py in translate(self, text, dest, src, **kwargs)
    180             jumps over  ->  이상 점프
    181             the lazy dog  ->  게으른 개
--> 182         """
    183         dest = dest.lower().split('_', 1)[0]
    184         src = src.lower().split('_', 1)[0]

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\client.py in _translate(self, text, dest, src, override)
     76             self.token_acquirer = TokenAcquirer(
     77                 client=self.client, host=self.service_urls[0])
---> 78 
     79             #if we have a service url pointing to client api we force the use of it as defaut client
     80             for t in enumerate(service_urls):

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\gtoken.py in do(self, text)
    192         if a < 0:  # pragma: nocover
    193             a = (a & 2147483647) + 2147483648
--> 194         a %= 1000000  # int(1E6)
    195 
    196         return '{}.{}'.format(a, a ^ b)

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\gtoken.py in _update(self)
     60 
     61         try:
---> 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'

@terryyz
Copy link
Collaborator Author

terryyz commented Mar 14, 2021

I am still having the same issue after installing googletrans==3.1.0a0

AttributeError                            Traceback (most recent call last)
<ipython-input-26-7d02fc64043f> in <module>
      1 from googletrans import Translator
      2 translator = Translator()
----> 3 print(translator.translate('أحبك', src='ar', dest= 'en'))

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\client.py in translate(self, text, dest, src, **kwargs)
    180             jumps over  ->  이상 점프
    181             the lazy dog  ->  게으른 개
--> 182         """
    183         dest = dest.lower().split('_', 1)[0]
    184         src = src.lower().split('_', 1)[0]

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\client.py in _translate(self, text, dest, src, override)
     76             self.token_acquirer = TokenAcquirer(
     77                 client=self.client, host=self.service_urls[0])
---> 78 
     79             #if we have a service url pointing to client api we force the use of it as defaut client
     80             for t in enumerate(service_urls):

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\gtoken.py in do(self, text)
    192         if a < 0:  # pragma: nocover
    193             a = (a & 2147483647) + 2147483648
--> 194         a %= 1000000  # int(1E6)
    195 
    196         return '{}.{}'.format(a, a ^ b)

~\Anaconda3\envs\python3.7\lib\site-packages\googletrans\gtoken.py in _update(self)
     60 
     61         try:
---> 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'

Hi @mzeidhassan, could you provide more information of your test environment. That translation actually worked for me at least...

@mzeidhassan
Copy link

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.

@myfreax
Copy link

myfreax commented Mar 16, 2021

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

@terryyz
Copy link
Collaborator Author

terryyz commented Mar 16, 2021

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

Oops, I think most of the service_urls don't actually work in this version. But I'll check the issue thoroughly.

What if you just try the default setting? Like:

from googletrans import Translator
translator = Translator()
tranlated = translator.translate('hello.', dest='zh-CN')
print(tranlated)

@myfreax
Copy link

myfreax commented Mar 16, 2021

from googletrans import Translator
translator = Translator()
tranlated = translator.translate('hello.', dest='zh-CN')
print(tranlated)

This code have the same

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    tranlated = translator.translate('hello.', dest='zh-CN')
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/client.py", line 182, in translate
    data = self._translate(text, dest, src, kwargs)
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/client.py", line 78, in _translate
    token = self.token_acquirer.do(text)
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 194, in do
    self._update()
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 62, in _update
    code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group

Have you tested it in new environment? But is not your dev environment

@terryyz
Copy link
Collaborator Author

terryyz commented Mar 16, 2021

from googletrans import Translator
translator = Translator()
tranlated = translator.translate('hello.', dest='zh-CN')
print(tranlated)

This code have the same

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    tranlated = translator.translate('hello.', dest='zh-CN')
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/client.py", line 182, in translate
    data = self._translate(text, dest, src, kwargs)
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/client.py", line 78, in _translate
    token = self.token_acquirer.do(text)
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 194, in do
    self._update()
  File "/home/scrapyd/venv/lib/python3.8/site-packages/googletrans/gtoken.py", line 62, in _update
    code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group

Have you tested it in new environment? But is not your dev environment

I'm testing on Ubuntu 20.04 python3.8.5 and it works for the default setting.

@myfreax
Copy link

myfreax commented Mar 16, 2021

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)

@terryyz
Copy link
Collaborator Author

terryyz commented Mar 16, 2021

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 :)

JaskaranSM added a commit to JaskaranSM/UniBorg that referenced this issue Mar 16, 2021
@dougsouza
Copy link

dougsouza commented Mar 16, 2021

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

@dangmanhtruong1995
Copy link

This worked, thanks a lot for your efforts !

@TheLastMonolith
Copy link

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

@ratthachat
Copy link

work for me in Colab environment! Thanks so much!!

@LostInDarkMath
Copy link

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?

@Bostwickenator
Copy link

I'm seeing the same behaviour @LostInDarkMath

@elfilalime
Copy link

The same problem @LostInDarkMath

@bianchi-dy
Copy link

Hi, I'm also getting the same issue even after changing the install version. On Python 3.7.6.

@ssut
Copy link
Owner

ssut commented May 6, 2021

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.

@gtkacz
Copy link

gtkacz commented May 13, 2021

Hey there! Gettting the same problem as @LostInDarkMath even when translating from english. Thanks for all your hard work!

@SwedishBarbarossa
Copy link

SwedishBarbarossa commented May 14, 2021

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 🙏

@vishnu4044
Copy link

after installing pip3 install googletrans==3.1.0a0.
still i'm not able to translate any text sir

my code
from googletrans import Translator
translator = Translator() # initalize the Translator object
translations = translator.translate('see if this helps', dest='hi') # translate two phrases to Hindi # print every translation
print(translations.text)

output:

see if this helps

@1shaked
Copy link

1shaked commented May 20, 2021

does not work for me, using python 3.8.3
I am getting AttributeError: 'NoneType' object has no attribute 'group'

@nduprincekc
Copy link

Mine is working now

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

Nnọọ.

@yevonnaelandrew
Copy link

yevonnaelandrew commented Dec 30, 2021

Working fine with me

!pip install googletrans==4.0.0rc1
from googletrans import Translator
translator = Translator()
translated = translator.translate(text='nama saya', dest='en')
print(translated.text)

If you just reinstalled the library, make sure to restart the runtime.

@VdeJong
Copy link

VdeJong commented Jan 13, 2022

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?

I had this too, but then I noticed the response code was a 429 (Too many requests). I guess Google stops translating if that occurs. Check the response code of the response if a text is not translated.

kinderp added a commit to kinderp/python-package-tutorial that referenced this issue Jan 20, 2022
v3.0.0 is affted by this bug not still solved
ssut/py-googletrans#280
@satwik-2001
Copy link

File "e:\python\speechrecognition.py", line 121, in
result = translator.translate('Mikä on nimesi', src='fi', dest='fr')
File "E:\python\venv\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "E:\python\venv\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "E:\python\venv\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "E:\python\venv\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

this error is coming for pip install googletrans==4.0.0rc1 also can any one help me out

@nrbnlulu
Copy link

use this library as it works fine

@laurinpaech
Copy link

I fixed it by updating my python version to 3.8.12

@frannylac
Copy link

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!

@v-danh
Copy link

v-danh commented Oct 22, 2023

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

It works, but I think this package is no longer updated, right?

@JPH71
Copy link

JPH71 commented Oct 22, 2023 via email

@v-danh
Copy link

v-danh commented Oct 23, 2023

You are right, I haven't updated it for a long while. I hope the new version of Google translate is compatible with python 2.7 I will lo9k it into it this week as I have some enhancements to do

Dear contributors!
Please consider removing Python 2x support (please see at https://devguide.python.org/versions)


On Sun, 22 Oct 2023, 16:12 Vu Duc Anh, @.> wrote: 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 <#234> I think this package is no longer updated, right? — Reply to this email directly, view it on GitHub <#280 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKI3AKIN6WSBW5DWWGBUJLDYAUSVZAVCNFSM4Y6KAES2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZXGQYTANRRG42A . You are receiving this because you commented.Message ID: @.>

@JPH71
Copy link

JPH71 commented Oct 23, 2023 via email

@black-six
Copy link

It works for me.

@Timothy1102
Copy link

version 3.1.0a0 not working for me. 4.0.0-rc1 works.

@ssut ssut unpinned this issue Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests