Python使用googletrans报错的解决方法
作者:tlanyan 时间:2021-09-21 01:38:00
问题
最近在工作中发现了一个问题,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)
曝出同样的错误。
解决办法
谷歌爸爸的翻译API接口进行了改动,让一票翻译的软件包不好使了。问题影响是全球性的,所以GayHub上很快就跟进讨论,并提交代码修复。代码在手,方案我有,三步操作让googletrans重新好使:
卸载已有的googletrans;
git克隆最新的代码;
安装包。
打开终端,三个命令搞定问题:
pip uninstall googletrans
git clone https://github.com/BoseCorp/py-googletrans.git
cd ./py-googletrans && python setup.py install
总结
参考
https://stackoverflow.com/questions/52455774/googletrans-stopped-working-with-error-nonetype-object-has-no-attribute-group
来源:https://www.tlanyan.me/python-googletrans-error/
标签:python,googletrans,报错
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python多进程程序打包成exe的问题
2023-08-07 13:39:03
淘宝网获亚洲最佳在线客户体验大奖
2009-03-31 12:55:00
![](https://img.aspxhome.com/file/UploadPic/20093/31/ued_090330-74s.jpg)
Python OpenCV之常用滤波器使用详解
2023-02-07 22:18:25
![](https://img.aspxhome.com/file/2023/9/81589_0s.jpg)
提醒各位一下,IE透明会失效的
2009-03-31 12:48:00
![](https://img.aspxhome.com/file/UploadPic/20093/31/icon_lol-37s.gif)
python map比for循环快在哪
2021-06-16 09:39:04
![](https://img.aspxhome.com/file/2023/7/88997_0s.png)
Python中的int函数使用
2023-05-13 06:11:59
CSS模块化设计—从空格谈起
2007-12-15 09:41:00
go特性之数组与切片的问题
2023-07-15 18:21:30
解决selenium模块利用performance获取network日志请求报错的问题(亲测有效)
2022-12-22 11:09:26
![](https://img.aspxhome.com/file/2023/9/86549_0s.jpg)
使用python检查yaml配置文件是否符合要求
2021-06-23 05:27:53
用户研究角度看设计(1)“复制链接”的故事
2008-12-26 17:48:00
MySQL数据库与表的最基本命令大盘点
2010-08-31 14:29:00
使用模板实现ASP代码与页面分离
2008-09-12 16:07:00
Python+matplotlib绘制饼图和堆叠图
2022-11-17 05:42:40
![](https://img.aspxhome.com/file/2023/4/86554_0s.png)
Autopep8的使用(python自动编排工具)
2022-07-04 11:10:47
![](https://img.aspxhome.com/file/2023/7/96967_0s.png)
一文带你了解Python中的字符串是什么
2021-10-16 06:05:27
![](https://img.aspxhome.com/file/2023/7/88987_0s.png)
浅谈ASP自动采集程序及入库
2007-08-17 11:25:00
使用NetBox 编译 asp 为exe应用程序
2009-11-29 16:13:00
如何利用python在剪贴板上读取/写入数据
2021-07-08 17:29:29
![](https://img.aspxhome.com/file/2023/5/90805_0s.png)
基于Python的图像数据增强Data Augmentation解析
2022-12-21 11:50:31
![](https://img.aspxhome.com/file/2023/1/87891_0s.jpg)