Search code examples
pythonpython-3.xgoogle-apitranslationgoogle-translate

How to fix: AttributeError: 'NoneType' object has no attribute 'group'


I am running the following code:-

from googletrans import Translator, constants
from pprint import print


# init the Google API translator
translator = Translator()

# translate a spanish text to english text (by default)
translation = translator.translate("Hola Mundo")


print("{} ({}) --> {} ({})".format(translation.origin, translation.src, translation.text, translation.dest))

While running this code, I got the error as : AttributeError: 'NoneType' object has no attribute 'group'

I can't figure out how to fix this error.

I have seen other answers on stackoverflow but those are not useful.

Does anyone know how to fix it?

Following is the screenshot of the complete error:- Error that I got after running this code


Solution

  • To fix this error, you have to uninstall the current googletrans version and install the new one using the following commands:

    pip3 uninstall googletrans
    pip3 install googletrans==3.1.0a0
    

    Run the code again and it should fix the error.