4

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?

0

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I am facing the same problem with but with Language Detection not translation. Can you please help me in understanding how can I do the same with the above format.
3

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.

Comments

0

You just need to set the from_lang parameter telling from which language you are translating:

en_blob = TextBlob(u'Simple is better than complex.')
print(en_blob.translate(from_lang='en', to='es'))

Comments

0

Introducing the from_lang parameter does not solve the issue, in my experience. I have fixed it calling Google's translation API from another front, not through textblob's. https://github.com/ssut/py-googletrans

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.