Python使用googletrans报错

栏目: Python · 发布时间: 6年前

内容简介:Python代码一直用着免费的Google翻译API插件单独写个测试:曝出同样的错误。

问题

Python代码一直用着免费的Google翻译API插件 googletrans ,这两天突然就报错了:

Traceback (most recent call last):
  File "xxx.py", line 5, in <module>
    result = translator.translate("Result from google translator", dest="zh-CN")
  File "/usr/lib/python3.4/site-packages/googletrans/client.py", line 172, in translate
    data = self._translate(text, dest, src)
  File "/usr/lib/python3.4/site-packages/googletrans/client.py", line 75, in _translate
    token = self.token_acquirer.do(text)
  File "/usr/lib/python3.4/site-packages/googletrans/gtoken.py", line 180, in do
    self._update()
  File "/usr/lib/python3.4/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'
 

单独写个测试:

from googletrans import Translator;
 
if __name__ == "__main__":
    translator = Translator()
    result = translator.translate("Result from google translator", dest="zh-CN")
    print(result.text)
 
    result = translator.translate("使用免费谷歌自动翻译API", dest="en")
    print(result.text)
 

曝出同样的错误。

Python使用googletrans报错

解决办法

谷歌爸爸的翻译API接口进行了改动,让一票翻译的软件包不好使了。问题影响是全球性的,所以GayHub上很快就跟进讨论,并提交代码修复。代码在手,方案我有,三步操作让 googletrans 重新好使:

googletrans

打开终端,三个命令搞定问题:

pip uninstall googletrans
git clone https://github.com/BoseCorp/py-googletrans.git
cd ./py-googletrans && python setup.py install
 

参考

  1. https://stackoverflow.com/questions/52455774/googletrans-stopped-working-with-error-nonetype-object-has-no-attribute-group

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Effective Python

Effective Python

布雷特·斯拉特金(Brett Slatkin) / 爱飞翔 / 机械工业出版社 / 2016-1 / 59

用Python编写程序,是相当容易的,所以这门语言非常流行。但若想掌握Python所特有的优势、魅力和表达能力,则相当困难,而且语言中还有很多隐藏的陷阱,容易令开发者犯错。 本书可以帮你掌握真正的Pythonic编程方式,令你能够完全发挥出Python语言的强大功能,并写出健壮而高效的代码。Scott Meyers在畅销书《Effective C++》中开创了一种以使用场景为主导的精练教学方......一起来看看 《Effective Python》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器