Skip to content

Instantly share code, notes, and snippets.

@ivansaul
Last active November 6, 2020 17:56
Show Gist options
  • Save ivansaul/a9084c49a954446c47731fad2ac3ee03 to your computer and use it in GitHub Desktop.
Save ivansaul/a9084c49a954446c47731fad2ac3ee03 to your computer and use it in GitHub Desktop.
Fix error in result (AttributeError: 'NoneType' object has no attribute 'group') GoogleTrans Python
'''
After making more than 10,000 queries, I realized that
each successful query takes a maximum of 15 iterations,
taking an average 1 second.
'''
import googletrans
from googletrans import Translator
def en_es(palabra):
translator = Translator()
i=1
while i<=20: #also you can try with while True:
try:
gtrans=translator.translate(palabra,dest="es")
except Exception as e:
translator = Translator()
i=i+1
else:
word=gtrans.text
break
return word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment