Last active
November 6, 2020 17:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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