0

I am new to Python. I have a problem but I do not know how to solve it.

My code:

from googletrans import Translator

translator: Translator = Translator()

result ='''The core library includes the data types, variables and literals, etc.
The standard library includes the set of functions manipulating strings, files, etc.
The Standard Template Library (STL) includes the set of methods manipulating a data structure.'''

dt = translator.detect(result)

print(dt)

And when I run the program and I get this error message:

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

How can I resolve this?

1 Answer 1

1

The way the googletrans library accesses Google Translate is not how Google wants people to access it, because it does some weird things that lets it pretend to be accessing it as a browser instead of getting an API key like they were supposed to. It looks like Google has changed something, which prevents the library from working. Your code is correct, but the library is broken.

If you were trying this because you wanted to play around with Python, I would recommend playing with some other library, because this one likely won't work for a while. If you really need to translate things, you can either look for another library that does something similar (but hopefully works), or you can use the official Google Translate API. However, just as a warning, the official API will not be easy for someone of your skill level to figure out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.