【问题标题】:I got error message AttributeError: 'NoneType' object has no attribute 'group' in pycharm for translate我收到错误消息 AttributeError: 'NoneType' object has no attribute 'group' in pycharm for translate
【发布时间】:2021-05-28 10:41:11
【问题描述】:

我是 Python 新手。我有一个问题,但我不知道如何解决。

我的代码:

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)

当我运行程序并收到以下错误消息:

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

我该如何解决这个问题?

【问题讨论】:

    标签: python translation google-translate translate


    【解决方案1】:

    googletrans 库访问谷歌翻译的方式并不是谷歌希望人们访问它的方式,因为它做了一些奇怪的事情,让它假装作为浏览器访问它,而不是像他们想象的那样获取 API 密钥到。看起来谷歌已经改变了一些东西,这阻止了图书馆的工作。您的代码是正确的,但库已损坏。

    如果你尝试这个是因为你想玩 Python,我建议你玩一些其他的库,因为这个库可能暂时不会工作。如果你真的需要翻译东西,你可以寻找另一个库做类似的事情(但希望能工作),或者你可以使用官方的谷歌翻译 API。但是,作为一个警告,官方 API 对于您的技能水平的人来说并不容易弄清楚。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      • 2017-10-20
      相关资源
      最近更新 更多