HTTPError: HTTP Error 503: Service Unavailable goslate language detection request : Python
Asked Answered
O

4

15

I have just started using the goslate library in Python to detect the language of the words in a text but after testing it for 7-8 inputs, I gave the input which had the words written in two languages, Arabic and English. After which, it started giving me the error.

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

I wrote the code as :

# -*- coding: utf8 -*-
import urllib2
import goslate


gs = goslate.Goslate()

language_id = gs.detect('wait الدولة')

print (gs.get_languages()[language_id])

and now it is not working at all for any input which I tested previously and is giving me same error. I tried finding error resolve on google but nothing helped. This is what I found : Link 1 - StackOverflow

I tried updating it with the command as also suggested in the link above :

pip install -U goslate

but it did not help as it is already the newest updated version that I am using. Also I read in the library documentation that one gets this kind of error for translation when :

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

I tried using proxy connection but nothing helped.

EDIT Could the reason be that Google allows only some number of requests per day ? In that case what better can be done ? Is there any other Python based library which can help me resolve this?

Olszewski answered 13/10, 2015 at 15:56 Comment(0)
P
10

In the documentation update from 05 of January of 2016, the author says that they will not update Goslate to overpass Google API access control :

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.

The official, Google-approved way to use Google Translate in your programs is with the paid Google Cloud Translation API. With anything else, you're going to be fighting Google's rate limiting and bot detection.

Peppercorn answered 24/2, 2016 at 19:6 Comment(0)
N
11

maybe looking for this: https://pypi.python.org/pypi/textblob it is better than goslate,

since textblob is blocked as of now, maybe py-translate could do the trick,

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!"

the first argument to the translator function is the source language, the second is the target language, and the third is the phrase to be translated,

it returns a dictionary, which the documentation refers to as a request interface

Nonentity answered 31/10, 2015 at 6:52 Comment(2)
No, this is also built on Google Translate API. You will encounter the same error. From textblob.py, line 34: url = "translate.google.com/translate_a/t"Choriocarcinoma
It gives me "requests.exceptions.HTTPError: 503 Server Error: Service Unavailable" error.Neptunium
P
10

In the documentation update from 05 of January of 2016, the author says that they will not update Goslate to overpass Google API access control :

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.

The official, Google-approved way to use Google Translate in your programs is with the paid Google Cloud Translation API. With anything else, you're going to be fighting Google's rate limiting and bot detection.

Peppercorn answered 24/2, 2016 at 19:6 Comment(0)
I
6

Elaborating on @programmer44 answer, here is an example of the use of TextBlob for this particular case:

from textblob.blob import TextBlob
blob = TextBlob('wait الدولة')
print(blob.detect_language())
Inescutcheon answered 5/5, 2016 at 15:38 Comment(2)
It gives me "urllib2.HTTPError: HTTP Error 503: Service Unavailable." error.Neptunium
@M.Mashaye Are you sure you have the latest version of Textblob?Inescutcheon
B
2

Since TextBlob does not seem to work for me anymore neither. I have use langdetect which works just fine.

As shown on their documentation:

from langdetect import detect

print detect("War doesn't show who's right, just who's left.")
print detect("Ein, zwei, drei, vier")

will return

en
de
Burrows answered 10/11, 2016 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.