Press "Enter" to skip to content

谷歌翻译插件报错(AttributeError: ‘NoneType’ object has no attribute ‘group’)

偶然机会需要用到Python来翻译资料,调研一番发现googletrans这个插件还不错。

安装好插件,尝试写了个demo

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# -*- coding: utf-8 -*-
from googletrans import Translator
translator = Translator(service_urls=[
'translate.google.com',
])
def translate(data):
response = translator.translate(data, dest='zh-CN')
return response.text
if __name__ == "__main__":
to_be_translate = '''
<p>In this tutorial, we'll learn how to use Filters.</p>
'''
response = translate(to_be_translate)
print(response)
# -*- coding: utf-8 -*- from googletrans import Translator translator = Translator(service_urls=[ 'translate.google.com', ]) def translate(data): response = translator.translate(data, dest='zh-CN') return response.text if __name__ == "__main__": to_be_translate = ''' <p>In this tutorial, we'll learn how to use Filters.</p> ''' response = translate(to_be_translate) print(response)
# -*- coding: utf-8 -*-
from googletrans import Translator

translator = Translator(service_urls=[
      'translate.google.com',
    ])

def translate(data):
  response = translator.translate(data, dest='zh-CN')
  return response.text  


if __name__ == "__main__":
  to_be_translate = '''

  <p>In this tutorial, we'll learn how to use Filters.</p> 

  '''
  response = translate(to_be_translate)
  print(response)

发现始终报错

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
AttributeError: 'NoneType' object has no attribute 'group'
AttributeError: 'NoneType' object has no attribute 'group'
AttributeError: 'NoneType' object has no attribute 'group'

最后查阅资料发现需要升级库的版本。。。

Hi guys
This problem has been solved in new version. please install 4.0.0rc1 version
pip install googletrans==4.0.0rc1

参考资料:

https://github.com/ssut/py-googletrans/issues/280#issuecomment-906161847

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注