Trying to detect language code in Python using googletrans. But it generating ERROR (Refer error block for info).
Require solution for the same
Code :
import googletrans
from googletrans import Translator
translator = Translator()
result = translator.translate('Mitä sinä teet')
print(result.src)
print(result.dest)
print(result.origin)
print(result.text)
print(result.pronunciation)
Error:
C:\ProgramData\Anaconda3\lib\site-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'
This is a known, reported issue in the
googletrans
library's github page. Take a look there to see the status of the fix and potential work arounds: https://github.com/ssut/py-googletrans/issues.According to the most recent comment, installing a different version,
googletrans==4.0.0-rc1
, appears to work, but with caveats: