Skip to content
Advertisement

Googletrans Error- The handshake operation timed out

When I try to translate text using the googletrans module, I get an error:

JavaScript

Here’s my code:

JavaScript

My code is very simple and I can’t figure out what’s wrong with it.

I tried changing the network connection, but it made no difference.

Is there any way to fix this problem?

It would be great if anyone could help me out.

Advertisement

Answer

Well that seems very much like an API error as google does not like when you send too much request, I cannot close this question either as the answer there is not an accepted one, anyway here is an alternative using deep_translator.

  • Start by installing it:
JavaScript
  • Now I recommend you take a stroll down its docs, but ill include an example using Google Translate anyway. Start by importing it:
JavaScript
  • Now create an initial instance of it, just to get the language map.
JavaScript
  • Now for the translation part, change your function to the following:
JavaScript

Yes creating a new instance every time function is run is not a good idea, but I couldn’t find another successful method to change the target language once it is initially set. It does not seem to give any error as of now, unless your source and target languages are both same.

On a side note, it is better to use threading, as sometimes the API might take time to respond and it will freeze the GUI.

Advertisement