I was trying googletrans
and it was working quite well. Since this morning I started getting below error. I went through multiple posts from stackoverflow and other sites and found probably my ip is banned to use the service for sometime. I tried using multiple service provider internet that has different ip and stil facing the same issue ? I also tried to use googletrans
on different laptops , still same issue ..Is googletrans
package broken or something google did at their end ?
>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate('안녕하세요.')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
translator.translate('안녕하세요.')
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'
Stevoisiak
22.1k27 gold badges119 silver badges216 bronze badges
asked Sep 22, 2018 at 10:29
3
Update 06.12.20: A new ‘official’ alpha version of googletrans with a fix was released
Install the alpha version like this:
pip install googletrans==3.1.0a0
Translation example:
translator = Translator()
translation = translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')
print(translation.text)
#output: 'The sky is blue and I like bananas'
In case it does not work, try to specify the service url like this:
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')
See the discussion here for details and updates: https://github.com/ssut/py-googletrans/pull/237
Update 10.12.20: Another fix was released
As pointed out by @DesiKeki and @Ahmed Breem, there is another fix which seems to work for several people:
pip install googletrans==4.0.0-rc1
Github discussion here: https://github.com/ssut/py-googletrans/issues/234#issuecomment-742460612
In case the fixes above don’t work for you
If the above doesn’t work for you, google_trans_new
seems to be a good alternative that works for some people. It’s unclear why the fix above works for some and doesn’t for others. See details on installation and usage here: https://github.com/lushan88a/google_trans_new
#pip install google_trans_new
from google_trans_new import google_translator
translator = google_translator()
translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')
print(translate_text)
#output: Hello china
answered Dec 2, 2020 at 13:46
MoritzMoritz
2,5152 gold badges6 silver badges11 bronze badges
11
Update 01/12/2020: This issue re-emerged lately, (apparently) caused once again by some changes on the Google translation API.
A solution is being discussed (again) in this Github issue. Although there is not a definitive solution yet a Pull Request seem to be solving the problem: https://github.com/ssut/py-googletrans/pull/237.
While we wait for it to be approved it can be installed like this:
$ 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
Original Answer:
Apparently it’s a recent and widespread problem on Google’s side.
Quoting various Github discussions, it happens when Google sends you directly the raw token.
It’s being discussed right now and there is already a pull request to fix it, so it should be resolved in the next few days.
For reference, see:
https://github.com/ssut/py-googletrans/issues/48 <— exact same problem reported on the Github repo
https://github.com/pndurette/gTTS/issues/60 <— seemingly same problem on a text-to-speech library
https://github.com/ssut/py-googletrans/pull/78 <— pull request to fix the issue
To apply this patch (without waiting for the pull request to be accepted) simply install the library from the forked repo https://github.com/BoseCorp/py-googletrans.git (uninstall the official library first):
$ pip uninstall googletrans
$ git clone https://github.com/BoseCorp/py-googletrans.git
$ cd ./py-googletrans
$ python setup.py install
You can clone it anywhere on your system and install it globally or while inside a virtualenv
.
answered Sep 22, 2018 at 11:23
MaldusMaldus
9,6544 gold badges22 silver badges35 bronze badges
18
Try google_trans_new. It solved the problem for me
https://github.com/lushan88a/google_trans_new
pip install google_trans_new
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!
Ian
3,3763 gold badges26 silver badges59 bronze badges
answered Dec 2, 2020 at 17:31
2
Updated Answer as of 2021 Sept
pip uninstall googletrans==4.0.0-rc1
pip install googletrans==3.1.0a0
The 3.1.0a0 version works with bulk translation too!
answered Sep 21, 2021 at 14:51
4
Unfortunately, I could get neither googletrans
nor google_trans_new
to work, despite the many proposed fixes that are around.
My solution was to switch to the deep_translator
package:
pip install -U deep-translator
Then you can use it like this:
>>> from deep_translator import GoogleTranslator
>>> GoogleTranslator(source='auto', target='de').translate("keep it up, you are awesome")
'weiter so, du bist toll'
See documentation for more info.
answered Jun 29, 2022 at 22:17
buddematbuddemat
3,90612 gold badges23 silver badges47 bronze badges
3
Update 10.12.20: New Alpha Version Release (Stable Release Candidate) is released: 4.0.0-rc1
It can be installed as follows:
pip install googletrans==4.0.0-rc1
Usage:
translation = translator.translate('이 문장은 한글로 쓰여졌습니다.', dest='en')
print(translation.text)
>>This sentence is written in Korean.
detected_lang = translator.detect('mein english me hindi likh raha hoon')
print(detected_lang)
>>Detected(lang=hi, confidence=None)
detected_lang = translator.detect('이 문장은 한글로 쓰여졌습니다.')
print(detected_lang)
>>Detected(lang=ko, confidence=None)
answered Dec 21, 2020 at 2:36
DesiKekiDesiKeki
5966 silver badges8 bronze badges
4
By the time of this answer, you can solve it with the following:
Uninstall your installed version of
pip uninstall googletrans
Install the following version
pip install googletrans==4.0.0rc1
I hope this will works for you as it worked for me.
You can try it now:
from googletrans import Translator
translator = Translator()
ar = translator.translate('مرحبا').text
print(ar)
Note that 4.0.0rc1 is using an old version of httpx
, if you are getting an error regarding that, you need to edit the file client.py, fix httpcore.SyncHTTPTransport
to httpcore.AsyncHTTPProxy
.
answered Jun 7, 2021 at 15:31
AKMalkadiAKMalkadi
5921 gold badge4 silver badges13 bronze badges
5
Here is an unofficial fix to this problem as Darkblader24 stated in: https://github.com/ssut/py-googletrans/pull/78
Update gtoken.py like this:
RE_TKK = re.compile(r'TKK=eval('((function(){(.+?)})())');',
re.DOTALL)
RE_RAWTKK = re.compile(r'TKK='([^']*)';',re.DOTALL)
def __init__(self, tkk='0', session=None, host='translate.google.com'):
self.session = session or requests.Session()
self.tkk = tkk
self.host = host if 'http' in host else 'https://' + host
def _update(self):
"""update tkk
"""
# we don't need to update the base TKK value when it is still valid
now = math.floor(int(time.time() * 1000) / 3600000.0)
if self.tkk and int(self.tkk.split('.')[0]) == now:
return
r = self.session.get(self.host)
rawtkk = self.RE_RAWTKK.search(r.text)
if rawtkk:
self.tkk = rawtkk.group(1)
return
answered Sep 24, 2018 at 20:49
KeremKerem
1,4532 gold badges15 silver badges27 bronze badges
1
Fixed is here https://pypi.org/project/py-translator/
$ pip3 install py_translator==1.8.9
from py_translator import Translator
s = Translator().translate(text='Hello my friend', dest='es').text
print(s)
out:Hola mi amigo
סטנלי גרונן
2,87923 gold badges48 silver badges66 bronze badges
answered Nov 18, 2018 at 14:35
0
pip uninstall googletrans googletrans-temp
pip install googletrans-temp
Worked for me in Win10 and Ubuntu 16 (Python 3.6) as of 2019.2.24 — Refer to one of the replies in https://github.com/ssut/py-googletrans/issues/94. The old fix pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade
does not work any more over here.
answered Oct 19, 2018 at 4:18
mikeymikey
1,9401 gold badge19 silver badges22 bronze badges
3
googletrans is not supported in latest python so you need to unistall it
install new googletrans ( pip install googletrans==3.1.0a0)
answered Jul 21, 2021 at 14:41
This is how I fixed my problem.
pip3 uninstall googletrans
pip3 install googletrans==3.1.0a0
First you need to uninstall the previous version and the install the 3.1.0 version.
Dharman♦
29.3k21 gold badges80 silver badges131 bronze badges
answered Oct 13, 2021 at 1:38
Use the translators package from here
- It works (;
- Supports more then google
Installation:
pip install translators --upgrade
Usage:
>>> import translators as ts
Using Israel server backend.
>>> ts.google('שלום' , to_language = 'es')
'Hola'
answered Feb 13, 2022 at 9:23
נירניר
1,0161 gold badge6 silver badges27 bronze badges
Making the following change to gtoken made it work for me:
RE_TKK = re.compile(r'tkk:'(.+?)'')
def __init__(self, tkk='0', session=None, host='translate.google.com'):
self.session = session or requests.Session()
self.tkk = tkk
self.host = host if 'http' in host else 'https://' + host
def _update(self):
"""update tkk
"""
# we don't need to update the base TKK value when it is still valid
r = self.session.get(self.host)
self.tkk = self.RE_TKK.findall(r.text)[0]
now = math.floor(int(time.time() * 1000) / 3600000.0)
if self.tkk and int(self.tkk.split('.')[0]) == now:
return
# this will be the same as python code after stripping out a reserved word 'var'
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
# unescape special ascii characters such like a x3d(=)
I obtained this snippet from the ticket here.
Note that this is slightly different from other change suggested earlier by Kerem.
For other uninitiated folks like me, gtoken.py can be found within AppDataLocalContinuumanaconda3site-packagesgoogletrans on a Windows machine using Anaconda. To find AppData, go into the address bar in file explorer, type ‘%AppData%’, and hit Enter.
answered Mar 28, 2019 at 16:12
It turns out putting the call whithin a try/except block solved the problem for me
try:
langs = translator.detect(update.message.text)
if langs.lang == 'en':
foo(translator.translate(update.message.text,dest='zh-cn').text)
else:
bar(translator.translate(update.message.text,dest='en').text)
except Exception as e:
print(e)
answered May 17, 2020 at 20:24
malemmalem
513 bronze badges
If you are using Google Colab or Jupyter Notebook, then run:
!pip uninstall googletrans
Restart the runtime, and then execute:
!pip install googletrans==4.0.0rc1
Azhar Khan
3,8068 gold badges26 silver badges32 bronze badges
answered Nov 25, 2022 at 6:48
Try — pip install googletrans==3.1.0a0
answered Sep 16, 2022 at 18:29
Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to use googletrans but I am facing following error googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ in Java. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
Contents
- How googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ Error Occurs ?
- How To Solve googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ Error ?
- Solution 1: Install latest version of googletrans
- Solution 2: Use google_trans_new
- Solution 3: Use this command
- Summary
I am trying to use googletrans
but I am facing following error.
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'
How To Solve googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ Error ?
- How To Solve googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ Error ?
To Solve googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ Error Install latest version of googletrans or Just use this version pip install googletrans==4.0.0-rc1 Now you can use google translate.
- googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’
To Solve googletrans AttributeError: ‘NoneType’ object has no attribute ‘group’ Error Install latest version of googletrans or Just use this version pip install googletrans==4.0.0-rc1 Now you can use google translate.
Solution 1: Install latest version of googletrans
Install latest version of googletrans or Just use this version.
pip install googletrans==4.0.0-rc1
Now you can use 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
Just use google_trans_new. To install use this command.
pip install google_trans_new
Here is simple 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: Use this 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
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
- ImportError: No module named _internal
Я написал несколько строк, используя функцию переводчика в Googletrans несколько дней назад. Но я пытался перезапустить эти строки сегодня, и это выдало ряд ошибок … Я действительно смущен этим. Если у вас возникла подобная проблема, пожалуйста, прокомментируйте ниже. Любая помощь приветствуется!
from googletrans import Translator
translator = Translator()
trans1 = translator.translate('Hello', dest = 'es')
Я получил следующую ошибку:
AttributeError Traceback (most recent call last)
<ipython-input-19-c0f9e5495a2f> in <module>()
----> 1 trans1 = translator.translate('Hello', dest = 'es')
~AppDataLocalContinuumanaconda3libsite-packagesgoogletransclient.py in translate(self, text, dest, src)
170
171 origin = text
--> 172 data = self._translate(text, dest, src)
173
174 # this code will be updated when the format is changed.
~AppDataLocalContinuumanaconda3libsite-packagesgoogletransclient.py in _translate(self, text, dest, src)
73 text = text.decode('utf-8')
74
---> 75 token = self.token_acquirer.do(text)
76 params = utils.build_params(query=text, src=src, dest=dest,
77 token=token)
~AppDataLocalContinuumanaconda3libsite-packagesgoogletransgtoken.py in do(self, text)
178
179 def do(self, text):
--> 180 self._update()
181 tk = self.acquire(text)
182 return tk
~AppDataLocalContinuumanaconda3libsite-packagesgoogletransgtoken.py in _update(self)
57 r = self.session.get(self.host)
58 # this will be the same as python code after stripping out a reserved word 'var'
---> 59 code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
60 # unescape special ascii characters such like a x3d(=)
61 if PY3: # pragma: no cover
AttributeError: 'NoneType' object has no attribute 'group'
Я пытался исследовать эту ошибку, но ничего не получил. Больше всего меня смутило то, что этот простой код прекрасно работал 3 дня назад. Но когда я открываюсь этим утром, я выскакивал ошибки. Пожалуйста помоги. Спасибо огромное!
4 ответа
Лучший ответ
Ниже приведено решение по этой ссылке.
Решение:
pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade
У меня это сработало отлично!
2
double-beep
11 Дек 2018 в 13:29
Обновите py-googletrans/googletrans/gtoken.py
следующим образом:
RE_TKK = re.compile(r'TKK=eval('((function(){(.+?)})())');',
re.DOTALL)
RE_RAWTKK = re.compile(r'tkk:'([^']*)'',re.DOTALL)
def __init__(self, tkk='0', session=None, host='translate.google.com'):
self.session = session or requests.Session()
self.tkk = tkk
self.host = host if 'http' in host else 'https://' + host
def _update(self):
"""update tkk
"""
# we don't need to update the base TKK value when it is still valid
now = math.floor(int(time.time() * 1000) / 3600000.0)
if self.tkk and int(self.tkk.split('.')[0]) == now:
return
r = self.session.get(self.host)
rawtkk = self.RE_RAWTKK.search(r.text)
if rawtkk:
self.tkk = rawtkk.group(1)
return
1
majran
2 Дек 2018 в 05:39
Google изменил способ создания токена. Там нет никакого исправления на момент написания. Вам нужно дождаться обновления googletrans.
0
Chris
22 Сен 2018 в 21:40