I have been using textblob
in Python 2.7.10 on Windows for quite some time, and unexpectedly, it stopped working. Testing with two independent virtual machines as well as on OS X produces the same error.
Testing a simple snippet from the docs:
from textblob import TextBlob
en_blob = TextBlob(u'Simple is better than complex.')
print(en_blob.translate(to='es'))
produces an error:
File "test.py", line 3, in <module> print(en_blob.translate(to='es')) File "C:\Python27\lib\site-packages\textblob\blob.py", line 509, in translate from_lang=from_lang, to_lang=to)) File "C:\Python27\lib\site-packages\textblob\translate.py", line 45, in translate raise NotTranslated('Translation API returned the input string unchanged.') textblob.exceptions.NotTranslated: Translation API returned the input string unchanged.
How can I debug this error?
As mentioned by @Gijs, the Google Translate API changed. This caused TextBlob's translation and language detection functionality to stop working.
I've submitted a PR to fix the problem.
As mentioned in the docs, Textblob uses the Google Translate API for its translations.
Apparently, this (undocumented) API changed it's output format. I am able to do a succesfull request with this snippet:
import requests
url = 'http://translate.google.com/translate_a/t'
params = {
"text": "Simple is better than complex",
"sl": "en",
"tl": "es",
"client": "p"
}
print(requests.get(url, params=params).content)
>> '"Simple es mejor que complejo"'
In the source code of textblob, code is indicating a json
encoded approach, but apparently Google has decided here that simple is indeed better than complex.
This issue is already mentioned in https://github.com/sloria/TextBlob/issues/117.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With