Answer the question
In order to leave comments, you need to log in
How to fix googletrans error?
This code, made according to one manual
from googletrans import Translator
translator = Translator()
def form_flags(reaction_name):
reaction_name = str.replace(reaction_name, ':', '', 2)
reaction_name = str.replace(reaction_name, 'f', '', 1)
reaction_name = str.replace(reaction_name, 'l', '', 1)
reaction_name = str.replace(reaction_name, 'a', '', 1)
reaction_name = str.replace(reaction_name, 'g', '', 1)
reaction_name = str.replace(reaction_name, '_', '', 1)
str(reaction_name)
return reaction_name
reaction = ":flag_ru:"
react_lang = form_flags(reaction)
print(react_lang)
message = "hello"
result = translator.translate(message, dest=react_lang)
final = result.text
print(final)
Traceback (most recent call last):
File "C:\Users\Ivan\DreamBot\dictionary.py", line 20, in <module>
result = translator.translate(message, dest=react_lang)
File "C:\Users\Ivan\DreamBot\venv\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\Ivan\DreamBot\venv\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\Ivan\DreamBot\venv\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\Ivan\DreamBot\venv\lib\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'
Answer the question
In order to leave comments, you need to log in
Use another library
- translators: https://github.com/UlionTse/translators/
- smallgoogletranslator (my library, and to be honest, the code there is disgusting :)) - https://github.com/MagM1go/GoogleTranslator
- Deep translator : https://pypi.org/project/deep-translator/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question