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

Question:

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

Asked By: Kapil Sharma

||

Answers:

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.

Answered By: Kapil Sharma

Installing using PyPI will install version 3.0.0, which has some errors. Later versions have been fixed. Installing version 3.1.0a0 or 4.0.0rc1 will solve the problem. Please uninstall and then specify the version to install.

pip uninstall googletrans
pip install googletrans==4.0.0rc1

Release history

Answered By: yunwoong