Windows 7
Python 3.8.2
谷歌翻译3.0.0
from googletrans import Translator
text = 'hello'
translator = Translator()
result = translator.translate(text).src
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:UsersABAppDataLocalProgramsPythonPython38-32libsite-packages
googletransclient.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:UsersABAppDataLocalProgramsPythonPython38-32libsite-packages
googletransclient.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:UsersABAppDataLocalProgramsPythonPython38-32libsite-packages
googletransgtoken.py", line 194, in do
self._update()
File "C:UsersABAppDataLocalProgramsPythonPython38-32libsite-packages
googletransgtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
在一切正常之前,过了一段时间,这些错误开始出现,现在每次函数调用后都会出现这个错误。
试试google_trans_new。https://github.com/lushan88a/google_trans_new
pip install google_trans_new
from google_trans_new import google_translator
translator = google_translator()
translate_text = translator.translate('Hello!',lang_src='en', lang_tgt='de')
print(translate_text)
->Hallo!
您必须通过键入pip-install-googletrans==4.0.0-rc1 将googletrans版本从3.0.0版本增加到4.0.0版本