Home > database >  Cannot use the Translator() function from googletrans module in Python
Cannot use the Translator() function from googletrans module in Python

Time:08-01

I'm using this code to translate the string 'Hola mundo':

text = 'Hola mundo'
from googletrans import Translator
Translator().translate(text) 

But I obtain this error:

AttributeError: 'NoneType' object has no attribute 'group'

I'm using Jupyter Notebook with Python version 3.9 and pip version 21.2.4.

Could someone help me with this issue? Thank you in advance!

CodePudding user response:

You have to create an instance of Translator to use this API

from googletrans import Translator
translator = Translator()
translator.translate(text)

CodePudding user response:

It works for me using version 4.0.0rc1. You can find a list of all versions here.

from googletrans import Translator


Translator().translate("Hola mundo").text # Output: 'Hello World'

The stable version 3.0.0 returns your error, which is a known bug.

  • Related