Reputation: 1450
I want to convert unknown language strings to English. For which I'm using googletrans
python package that works along with an API to perform the desired task
So, I did following
from googletrans import Translator
translator = Translator()
translator.translate('안녕하세요.', dest='ja')
This gave
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-9a3706f65a29> in <module>()
1 from googletrans import Translator
2 translator = Translator()
----> 3 translator.translate('안녕하세요.', dest='ja')
3 frames
/usr/local/lib/python3.7/dist-packages/googletrans/client.py in translate(self, text, dest, src, **kwargs)
180
181 origin = text
--> 182 data = self._translate(text, dest, src, kwargs)
183
184 # this code will be updated when the format is changed.
/usr/local/lib/python3.7/dist-packages/googletrans/client.py in _translate(self, text, dest, src, override)
76
77 def _translate(self, text, dest, src, override):
---> 78 token = self.token_acquirer.do(text)
79 params = utils.build_params(query=text, src=src, dest=dest,
80 token=token, override=override)
/usr/local/lib/python3.7/dist-packages/googletrans/gtoken.py in do(self, text)
192
193 def do(self, text):
--> 194 self._update()
195 tk = self.acquire(text)
196 return tk
/usr/local/lib/python3.7/dist-packages/googletrans/gtoken.py in _update(self)
60
61 # this will be the same as python code after stripping out a reserved word 'var'
---> 62 code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
63 # unescape special ascii characters such like a \x3d(=)
64 code = code.encode().decode('unicode-escape')
AttributeError: 'NoneType' object has no attribute 'group'
What is causing the error? Is there any other way around to achieve the task.
Upvotes: 1
Views: 7072
Reputation: 1064
Try installing the below version of googletrans;
pip install googletrans==3.1.0a0
This would work!
Upvotes: 0
Reputation: 2974
As I have tested your scenario using your code, I also encountered the same error as seen in this screenshot.
This is likely due to the old library version that you're using which is googletrans 3.0.0
To resolve the issue you are encountering, you must upgrade your googletrans from 3.0.0 to 4.0.0rc1. You may use below script to upgrade your googletrans version.
pip install googletrans==4.0.0rc1
Please see below successful testing using googletrans 4.0.0rc1 for your reference:
Upvotes: 10