HTTPError: HTTP Error 503: Service Unavailable goslate language detection request : Python
HTTPError: HTTP Error 503: Service Unavailable goslate language detection request : Python
我刚开始使用 Python 中的 goslate 库来检测文本中单词的语言,但在测试了 7-8 个输入后,我给出了包含两个单词的输入语言,阿拉伯语和英语。之后,它开始给我错误。
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
execfile("C:/test_goslate.py");
File "C:/test_goslate.py", line 12, in <module>
language_id = gs.detect('الدولة')
File "C:\Python27\lib\site-packages\goslate.py", line 484, in detect
return self._detect_language(text)
File "C:\Python27\lib\site-packages\goslate.py", line 448, in _detect_language
return self._basic_translate(text[:50].encode('utf-8'), 'en', 'auto')[1]
File "C:\Python27\lib\site-packages\goslate.py", line 251, in _basic_translate
response_content = self._open_url(url)
File "C:\Python27\lib\site-packages\goslate.py", line 181, in _open_url
response = self._opener.open(request, timeout=self._TIMEOUT)
File "C:\Python27\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 503: Service Unavailable
我把代码写成:
# -*- coding: utf8 -*-
import urllib2
import goslate
gs = goslate.Goslate()
language_id = gs.detect('wait الدولة')
print (gs.get_languages()[language_id])
现在它对我之前测试过的任何输入都不起作用并且给我同样的错误。
我尝试在 google 上查找错误解决方案,但无济于事。这是我发现的:
我尝试使用上面 link 中建议的命令更新它:
pip install -U goslate
但它没有帮助,因为它已经是我正在使用的最新更新版本。我还在图书馆文档中读到,在以下情况下会出现这种翻译错误:
If you get HTTP 5xx error, it is probably because google has banned your client IP address from transation querying.
You could verify it by access google translation service in browser manually.
You could try the following to overcome this issue:
query through a HTTP/SOCK5 proxy, see Proxy Support
using another google domain for translation: gs = Goslate(service_urls=['http://translate.google.de'])
wait for 3 seconds before issue another querying
我尝试使用代理连接但没有任何帮助。
编辑
原因可能是 Google 每天只允许一定数量的请求吗?在那种情况下,可以做些什么更好?有没有其他基于 Python 的库可以帮助我解决这个问题?
也许正在寻找这个:https://pypi.python.org/pypi/textblob它比 goslate 好,
由于 textblob 目前已被阻止,也许 py-translate 可以解决这个问题,
https://pypi.python.org/pypi/py-translate/#downloads
http://pythonhosted.org/py-translate/devs/api.html
from translate import translator
translator('en', 'es', 'Hello World!')
"py-translate is a CLI Tool for Google Translate written in Python!"
翻译函数的第一个参数是源语言,第二个是目标语言,第三个是要翻译的短语,
它 returns 一个字典,文档将其称为请求接口
在2016年1月05日的文档更新中,作者说他们不会更新Goslate来立交桥Google API访问控制:
Google has updated its translation service recently with a ticket mechanism to prevent simple crawler program like goslate from accessing. Though a more sophisticated crawler may still work technically, however it would have crossed the fine line between using the service and breaking the service. goslate will not be updated to break google’s ticket mechanism. Free lunch is over. Thanks for using.
Google 官方批准在您的程序中使用 Google Translate 的方式是付费 Google Cloud Translation API。与其他任何事情一样,您将与 Google 的速率限制和机器人检测作斗争。
详细说明@programmer44 的回答,这里是针对此特定情况使用 TextBlob 的示例:
from textblob.blob import TextBlob
blob = TextBlob('wait الدولة')
print(blob.detect_language())
因为 TextBlob 似乎也不再适合我了。我使用了 langdetect,效果很好。
如他们的文档所示:
from langdetect import detect
print detect("War doesn't show who's right, just who's left.")
print detect("Ein, zwei, drei, vier")
将return
en
de
我刚开始使用 Python 中的 goslate 库来检测文本中单词的语言,但在测试了 7-8 个输入后,我给出了包含两个单词的输入语言,阿拉伯语和英语。之后,它开始给我错误。
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
execfile("C:/test_goslate.py");
File "C:/test_goslate.py", line 12, in <module>
language_id = gs.detect('الدولة')
File "C:\Python27\lib\site-packages\goslate.py", line 484, in detect
return self._detect_language(text)
File "C:\Python27\lib\site-packages\goslate.py", line 448, in _detect_language
return self._basic_translate(text[:50].encode('utf-8'), 'en', 'auto')[1]
File "C:\Python27\lib\site-packages\goslate.py", line 251, in _basic_translate
response_content = self._open_url(url)
File "C:\Python27\lib\site-packages\goslate.py", line 181, in _open_url
response = self._opener.open(request, timeout=self._TIMEOUT)
File "C:\Python27\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 503: Service Unavailable
我把代码写成:
# -*- coding: utf8 -*-
import urllib2
import goslate
gs = goslate.Goslate()
language_id = gs.detect('wait الدولة')
print (gs.get_languages()[language_id])
现在它对我之前测试过的任何输入都不起作用并且给我同样的错误。
我尝试在 google 上查找错误解决方案,但无济于事。这是我发现的:
我尝试使用上面 link 中建议的命令更新它:
pip install -U goslate
但它没有帮助,因为它已经是我正在使用的最新更新版本。我还在图书馆文档中读到,在以下情况下会出现这种翻译错误:
If you get HTTP 5xx error, it is probably because google has banned your client IP address from transation querying.
You could verify it by access google translation service in browser manually.
You could try the following to overcome this issue:
query through a HTTP/SOCK5 proxy, see Proxy Support
using another google domain for translation: gs = Goslate(service_urls=['http://translate.google.de'])
wait for 3 seconds before issue another querying
我尝试使用代理连接但没有任何帮助。
编辑 原因可能是 Google 每天只允许一定数量的请求吗?在那种情况下,可以做些什么更好?有没有其他基于 Python 的库可以帮助我解决这个问题?
也许正在寻找这个:https://pypi.python.org/pypi/textblob它比 goslate 好,
由于 textblob 目前已被阻止,也许 py-translate 可以解决这个问题,
https://pypi.python.org/pypi/py-translate/#downloads
http://pythonhosted.org/py-translate/devs/api.html
from translate import translator
translator('en', 'es', 'Hello World!')
"py-translate is a CLI Tool for Google Translate written in Python!"
翻译函数的第一个参数是源语言,第二个是目标语言,第三个是要翻译的短语,
它 returns 一个字典,文档将其称为请求接口
在2016年1月05日的文档更新中,作者说他们不会更新Goslate来立交桥Google API访问控制:
Google has updated its translation service recently with a ticket mechanism to prevent simple crawler program like goslate from accessing. Though a more sophisticated crawler may still work technically, however it would have crossed the fine line between using the service and breaking the service. goslate will not be updated to break google’s ticket mechanism. Free lunch is over. Thanks for using.
Google 官方批准在您的程序中使用 Google Translate 的方式是付费 Google Cloud Translation API。与其他任何事情一样,您将与 Google 的速率限制和机器人检测作斗争。
详细说明@programmer44 的回答,这里是针对此特定情况使用 TextBlob 的示例:
from textblob.blob import TextBlob
blob = TextBlob('wait الدولة')
print(blob.detect_language())
因为 TextBlob 似乎也不再适合我了。我使用了 langdetect,效果很好。
如他们的文档所示:
from langdetect import detect
print detect("War doesn't show who's right, just who's left.")
print detect("Ein, zwei, drei, vier")
将return
en
de