问题描述
我正在尝试 googletrans
并且效果很好.从今天早上开始,我开始出现以下错误.我浏览了来自 stackoverflow 和其他网站的多篇帖子,发现我的 ip 可能在一段时间内被禁止使用该服务.我尝试使用具有不同 IP 的多个服务提供商互联网,但仍然面临相同的问题?我还尝试在不同的笔记本电脑上使用 googletrans
,仍然是同样的问题..googletrans
包是否损坏了或者谷歌在他们的最后做了什么?
Update 01/12/2020: 这个问题最近再次出现,(显然)是由 Google 的一些更改再次引起的翻译 API.
在这个 Github 问题中(再次)讨论了一个解决方案.虽然还没有明确的解决方案,但 Pull Request 似乎正在解决问题:https://github.com/ssut/py-googletrans/pull/237.
当我们等待它被批准时,它可以像这样安装:
$ pip 卸载 googletrans$ git clone https://github.com/alainrouillon/py-googletrans.git$ cd ./py-googletrans$ git checkout origin/feature/enhance-use-of-direct-api$ python setup.py 安装
原答案:
显然,这是 Google 方面最近普遍存在的问题.引用 Github 的各种讨论,当 Google 直接向您发送原始令牌时就会发生这种情况.
目前正在讨论中,已经有一个拉取请求来修复它,所以应该会在接下来的几天内解决.
参考:
https://github.com/ssut/py-googletrans/issues/48 <-- 与 Github 存储库报告的问题完全相同https://github.com/pndurette/gTTS/issues/60 <--文本转语音库上看似相同的问题https://github.com/ssut/py-googletrans/pull/78<-- 拉取请求以解决问题
要应用此补丁(无需等待拉取请求被接受),只需从分叉存储库安装库 https://github.com/BoseCorp/py-googletrans.git(先卸载官方库):
$ pip 卸载 googletrans$ git clone https://github.com/BoseCorp/py-googletrans.git$ cd ./py-googletrans$ python setup.py 安装
您可以在系统上的任何位置克隆它并在全局或在 virtualenv
中安装它.
I was trying googletrans
and it was working quite well. Since this morning I started getting below error. I went through multiple posts from stackoverflow and other sites and found probably my ip is banned to use the service for sometime. I tried using multiple service provider internet that has different ip and stil facing the same issue ? I also tried to use googletrans
on different laptops , still same issue ..Is googletrans
package broken or something google did at their end ?
>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate('안녕하세요.')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
translator.translate('안녕하세요.')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/client.py", line 172, in translate
data = self._translate(text, dest, src)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/client.py", line 75, in _translate
token = self.token_acquirer.do(text)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/gtoken.py", line 180, in do
self._update()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/gtoken.py", line 59, in _update
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
Update 01/12/2020: This issue re-emerged lately, (apparently) caused once again by some changes on the Google translation API.
A solution is being discussed (again) in this Github issue. Although there is not a definitive solution yet a Pull Request seem to be solving the problem: https://github.com/ssut/py-googletrans/pull/237.
While we wait for it to be approved it can be installed like this:
$ pip uninstall googletrans
$ git clone https://github.com/alainrouillon/py-googletrans.git
$ cd ./py-googletrans
$ git checkout origin/feature/enhance-use-of-direct-api
$ python setup.py install
Original Answer:
Apparently it's a recent and widespread problem on Google's side.Quoting various Github discussions, it happens when Google sends you directly the raw token.
It's being discussed right now and there is already a pull request to fix it, so it should be resolved in the next few days.
For reference, see:
https://github.com/ssut/py-googletrans/issues/48 <-- exact same problem reported on the Github repohttps://github.com/pndurette/gTTS/issues/60 <-- seemingly same problem on a text-to-speech libraryhttps://github.com/ssut/py-googletrans/pull/78 <-- pull request to fix the issue
To apply this patch (without waiting for the pull request to be accepted) simply install the library from the forked repo https://github.com/BoseCorp/py-googletrans.git (uninstall the official library first):
$ pip uninstall googletrans
$ git clone https://github.com/BoseCorp/py-googletrans.git
$ cd ./py-googletrans
$ python setup.py install
You can clone it anywhere on your system and install it globally or while inside a virtualenv
.
这篇关于googletrans 因错误“NoneType"对象没有属性“group"而停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!