py-googletrans icon indicating copy to clipboard operation
py-googletrans copied to clipboard

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

Open terryyz opened this issue 4 years ago • 57 comments

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 avatar Mar 10 '21 15:03 terryyz

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'

mzeidhassan avatar Mar 14 '21 20:03 mzeidhassan

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...

terryyz avatar Mar 14 '21 23:03 terryyz

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.

mzeidhassan avatar Mar 15 '21 15:03 mzeidhassan

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

myfreax avatar Mar 16 '21 02:03 myfreax

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)

terryyz avatar Mar 16 '21 03:03 terryyz

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

myfreax avatar Mar 16 '21 03:03 myfreax

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.

terryyz avatar Mar 16 '21 03:03 terryyz

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)

myfreax avatar Mar 16 '21 03:03 myfreax

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

terryyz avatar Mar 16 '21 03:03 terryyz

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

dougsouza avatar Mar 16 '21 16:03 dougsouza

This worked, thanks a lot for your efforts !

dangmanhtruong1995 avatar Mar 24 '21 08:03 dangmanhtruong1995

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

TheLastMonolith avatar Mar 29 '21 13:03 TheLastMonolith

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

ratthachat avatar Apr 01 '21 09:04 ratthachat

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?

LostInDarkMath avatar Apr 02 '21 14:04 LostInDarkMath

I'm seeing the same behaviour @LostInDarkMath

Bostwickenator avatar Apr 03 '21 15:04 Bostwickenator

The same problem @LostInDarkMath

elfilalime avatar Apr 03 '21 18:04 elfilalime

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

bianchi-dy avatar Apr 16 '21 15:04 bianchi-dy

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.

ssut avatar May 06 '21 05:05 ssut

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

gtkacz avatar May 13 '21 23:05 gtkacz

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

SwedishBarbarossa avatar May 14 '21 15:05 SwedishBarbarossa

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

vishnu4044 avatar May 15 '21 09:05 vishnu4044

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

1shaked avatar May 20 '21 12:05 1shaked

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

Bostwickenator avatar May 20 '21 20:05 Bostwickenator

do you know why pip still points to 3.0?

evan54 avatar May 21 '21 02:05 evan54

do you know why pip still points to 3.0?

https://pip.pypa.io/en/stable/cli/pip_install/#pre-release-versions

Bostwickenator avatar May 21 '21 02:05 Bostwickenator

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

python -m pip install --pre googletrans

mzeidhassan avatar May 26 '21 20:05 mzeidhassan

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.

HubKing avatar Jul 04 '21 00:07 HubKing

I just installed the version 4.0.0rc1 with python 3.7.6 and I still get same error anything else I need to do ?

liliana3186 avatar Jul 09 '21 21:07 liliana3186

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

oleksandrsirenko avatar Jul 15 '21 23:07 oleksandrsirenko

When I try to install I get this error message pip install googletrans==3.1.0a0

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. ERROR: Could not find a version that satisfies the requirement googletrans==3.1.0a0 (from versions: 2.0.0, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2.0, 2.3.0, 2.4.0, 3.0.0) ERROR: No matching distribution found for googletrans==3.1.0a0

JPH71 avatar Jul 16 '21 01:07 JPH71