为什么python googletrans突然无法正常工作? [英] why python googletrans suddenly not working?

查看:89
本文介绍了为什么python googletrans突然无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

# coding: utf-8
from googletrans import Translator
translator = Translator()
print translator.translate('here', dest='zh-CN')

一切都在今天之前进行得很顺利.但不是我尝试使用此python库.然后我得到了这个错误.

everything goes well before today. But not I try to use this python library. then I got this error.

root@localhost:~# python googletest.py 
Traceback (most recent call last):
  File "googletest.py", line 4, in <module>
    print translator.translate(u'here', dest='zh-CN')
  File "/usr/local/lib/python2.7/dist-packages/googletrans/client.py", line 132, in translate
    data = self._translate(text, dest, src)
  File "/usr/local/lib/python2.7/dist-packages/googletrans/client.py", line 57, in _translate
    token = self.token_acquirer.do(text)
  File "/usr/local/lib/python2.7/dist-packages/googletrans/gtoken.py", line 180, in do
    self._update()
  File "/usr/local/lib/python2.7/dist-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'

有人知道发生了什么吗?谢谢.

Does anyone know what is going on? thank you.

这是库URL https://py-googletrans.readthedocs.io/en/latest/

推荐答案

如果您深入阅读图书馆,您对Google翻译网站的请求将返回类似503错误或其他错误的信息.对我来说是503错误和文字:

If you go deeper to library you see, that request to google translate site returns something like 503 error or other. For me it was 503 error and text:

This page appears when Google automatically detects requests coming from 
your computer network which appear to be in violation of the Terms of Service.
The block will expire shortly after those requests stop.

This traffic may have been sent by malicious software, a browser plug-in, 
or ascript that sends automated requests. If you share your network connection,
ask your administrator for help — a different computer using the same IP
address may be responsible. Learn more

Sometimes you may see this page if you are using advanced terms that robots
are known to use, or sending requests very quickly.

这意味着项目的README会说:

This means, and README of project says it:

如果您收到HTTP 5xx错误或类似#6的错误,则可能是因为Google禁止了您的客户端IP地址.

If you get HTTP 5xx error or errors like #6, it’s probably because Google has banned your client IP address.

尝试使用代理.

这篇关于为什么python googletrans突然无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆