py-googletrans
py-googletrans copied to clipboard
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
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'
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...
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.
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
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.5from 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)
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
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 'groupHave 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.
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)
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 wrokfrom 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 :)
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, thanks a lot for your efforts !
googletrans==3.1.0a0 at python version 3.8.5 doesn't work for me.
work for me in Colab environment! Thanks so much!!
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'm seeing the same behaviour @LostInDarkMath
The same problem @LostInDarkMath
Hi, I'm also getting the same issue even after changing the install version. On Python 3.7.6.
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.
Hey there! Gettting the same problem as @LostInDarkMath even when translating from english. Thanks for all your hard work!
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:
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
does not work for me, using python 3.8.3 I am getting AttributeError: 'NoneType' object has no attribute 'group'
Hey all, just jump up to the 4.0.0rc1 release it works.
do you know why pip still points to 3.0?
do you know why pip still points to 3.0?
https://pip.pypa.io/en/stable/cli/pip_install/#pre-release-versions
For those who want to install 4.0.0rc1, you can use this command:
python -m pip install --pre googletrans
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.
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 ?
Same error, neither version 3.1.0a0 nor 4.0.0rc1 works.
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