2

So I have been trying out coding and am currently finding some language detection packages and found out about textblob, but I am having some sort of proble. This is my code:

# - *- coding: utf- 8 - *-
from textblob import TextBlob

blob = TextBlob("Comment vas-tu?")

print(blob.detect_language())

print(blob.translate(to='es'))
print(blob.translate(to='en'))
print(blob.translate(to='zh'))

and this error shows:

Traceback (most recent call last):
  File "C:\Users\*****\PycharmProjects\pythonProject\main.py", line 6, in <module>
    print(blob.detect_language())
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\site-packages\textblob\blob.py", line 568, in detect_language
    return self.translator.detect(self.raw)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\site-packages\textblob\translate.py", line 72, in detect
    response = self._request(url, host=host, type_=type_, data=data)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\site-packages\textblob\translate.py", line 92, in _request
    resp = request.urlopen(req)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Process finished with exit code 1

I am still a little bit of a beginner in programming... Can I ask what I can do to solve this?

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Sep 23, 2021 at 14:31

2 Answers 2

0

You can make it working by doing some changes in your translate.py file as mentioned below: Original:

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 to:

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"

For further details visit this link: "HTTPError: HTTP Error 404: Not Found" while using translation function in TextBlob

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

Comments

0

Since you only need to do language detection, I see that langdetect library is a good fit: https://pypi.org/project/langdetect/

Here is a demo on how to use it:

>>> from langdetect import detect
>>> detect('هيا بنا نلعب')
'ar'
>>>

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.