0

I made a code that translates a word a lot of times to see what will be the word at the end, and sometimes it gives the error. Can anyone help me with it and also if there is a fix to make the code faster because it's very slow.

The code:

import googletrans
import random

languages = ['af', 'sq', 'am', 'ar', 'hy', 'az', 'eu', 'be', 'bn', 'bs', 'bg', 'ca', 'ceb', 'ny', 'zh-cn', 'zh-tw', 'co', 'hr', 'cs', 'da', 'nl', 'en', 'eo', 'et', 'tl', 'fi', 'fr', 'fy', 'gl', 'ka', 'de', 'el', 'gu', 'ht', 'haw', 'iw', 'he', 'hi', 'hmn', 'hu', 'is', 'ig', 'id', 'ga', 'it', 'ja', 'jw', 'kn', 'kk', 'km', 'ko', 'ku', 'lo', 'la', 'lv', 'lt']

word = input("Entrer the word: ")

translator = googletrans.Translator()

result = translator.translate(word, dest=random.choice(languages), src='auto')

ancient = 'en'

j = 10

for x in range(j):
  c = random.choice(languages)
  print(f"{x + 1} / {j}")
  
  result = translator.translate(result.text, dest=c, src='auto')

  result = translator.translate(result.text, dest=ancient, src='auto')
  
  print("")
  ancient = c

result = translator.translate(result.text, dest='en', src='auto')

print(result.text)

I don't know how to change the timeout of the translation fonction, please help me

pirosow
  • 13
  • 3
  • Most likely, Google is blocking your IP due to sending repeated requests. You should instead use the official Google Translate API. Duplicate of : https://stackoverflow.com/questions/72375391/httpcore-exceptions-readtimeout-the-read-operation-timed-out-python-googletr and https://stackoverflow.com/questions/65279841/googletrans-throws-a-connecttimeout-error-the-handshake-operation-timed-out/ – nigh_anxiety Apr 17 '23 at 04:31

0 Answers0