4

When I try to use translate function in TextBlob library in jupyter notebook, I get:

HTTPError: HTTP Error 404: Not Found

I have posted my code and screenshot of error message for reference here. This code worked well 5-6 days ago when I ran exactly the same code first time but after that whenever I run this code it gives me the same error message. I have been trying to run this code since last 4-5 days but it never worked again.

My code:

from textblob import TextBlob

en_blob = TextBlob('Simplilearn is one of the world’s leading certification training providers.')

en_blob.translate(to='es')  

I am new to stackoverflow and asking my first question on this plateform so please pardon me if I my question is not following rules of this platform.

saedx1
  • 984
  • 6
  • 20
Manish
  • 130
  • 1
  • 12
  • could you please add more verbose exception output (with traceback)? – 0dminnimda Sep 26 '21 at 22:42
  • 1
    I have finally found the solution to above problem after doing some googling and is posted below. Thanks for taking out your time to look into my question. – Manish Sep 28 '21 at 19:57

3 Answers3

5

Textblob library uses Google API for translation functionality in the backend. Google has made some changes in the its API recently. Due to this reason TextBlob's translation feature has stopped working. I noticed that by making some minor changes in translate.py file (in your folder where all TextBlob files are located) as mentioned below, we can get rid of this error:

original code:

url = "http://translate.google.com/translate_a/t?client=webapp&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"

change above code in translate.py to following:

url = "http://translate.google.com/translate_a/t?client=te&format=html&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"
Manish
  • 130
  • 1
  • 12
0

I have just tried this. It did not work for me the first times.

I restarted the Anaconda Prompt, restarted IPython. And re-ran my snippets and the problem go away after the fix. I am using Windows 10, I don't use virtual environment, the two files that were changed are:

C:\Users\behai\anaconda3\pkgs\textblob-0.15.3-py_0\site-packages\textblob\translate.py
C:\Users\behai\anaconda3\Lib\site-packages\textblob\translate.py

And I have also found that I have to do tab-indentation for the newline.

Added on 02/01/2021:

I did not do anything much at all. I applied the suggestion by Mr. Manish ( green tick above ). I had this 404 problem in the Anaconda environment. After applied the change above, I just restarted the "Anaconda Prompt (anaconda3)", and it worked.

This is the change as suggested above, in:

C:\Users\behai\anaconda3\Lib\site-packages\textblob\translate.py
    # url = "http://translate.google.com/translate_a/t?client=webapp&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"
    url = "http://translate.google.com/translate_a/t?client=te&format=html&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1"

The file below get auto-updated:

C:\Users\behai\anaconda3\pkgs\textblob-0.15.3-py_0\site-packages\textblob\translate.py
  • I'm not sure this really answers the question – moo Jan 01 '22 at 13:03
  • Can you please elaborate further what you did and post clear solutions tried by you so that it can help others too. – Manish Jan 01 '22 at 21:33
  • Hi, I have updated my answer above with **Added on 02/01/2021:**. Thank you and best regards. –  Jan 02 '22 at 02:16
0

It's fixed at https://github.com/sloria/TextBlob/pull/398

You should use a tag version with that fix.

# requirements/txt
textblob @ git+https://github.com/sloria/TextBlob@0.17.1#=textBlob