Reputation: 23
When using this code from https://stackabuse.com/text-translation-with-google-translate-api-in-python/
from googletrans import Translator
translator = Translator()
result = translator.translate("Mitä sinä teet")
print(result.src)
print(result.dest)
print(result.origin)
print(result.text)
I get 'AttributeError: 'NoneType' object has no attribute 'group'', and i was wondering what is wrong, the error seems to be on the 'result = tra...' line,
Thank you for any help
Upvotes: 2
Views: 1814
Reputation: 1063
with open(os.path.join(files_from_folder, filename), encoding='utf-8') as html:
soup = BeautifulSoup('<pre>' + html.read() + '</pre>', 'html.parser')
for title in soup.findAll('title'):
recursively_translate(title)
See this 2 complete code that can easy translate files with python:
OR
https://neculaifantanaru.com/en/example-python-google-translate-any-text-html-file-version-2.html
Upvotes: 0
Reputation: 61
I think the problem is with the installation of the library because the code worked fine for me. I would suggest you to uninstall and then reinstall the googletrans library.
Upvotes: 0
Reputation: 395
Ok, I was too getting this same error. I think there is a issue in the current release. But the new alpha version worked fine.
First uninstall current version :
pip uninstall googletrans
Then install this one :
pip install googletrans==3.1.0a0
Upvotes: 1