Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error intranslation #395

Closed
mannan291 opened this issue Sep 11, 2021 · 12 comments
Closed

error intranslation #395

mannan291 opened this issue Sep 11, 2021 · 12 comments

Comments

@mannan291
Copy link

url not found error sometime:

File "/usr/local/lib/python3.8/dist-packages/textblob/blob.py", line 546, in translate
return self.class(self.translator.translate(self.raw,
File "/usr/local/lib/python3.8/dist-packages/textblob/translate.py", line 54, in translate
response = self.request(url, host=host, type=type_, data=data)
File "/usr/local/lib/python3.8/dist-packages/textblob/translate.py", line 92, in _request
resp = request.urlopen(req)
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

@IIWesleyII
Copy link

I am having the same issue. it worked a week ago, now I'm receiving a 404 error whenever I call detect_language()

@mannan291
Copy link
Author

i thought it might be the issue regarding urllib.requests, so I changed the method of request through "requests", but the error was the same.
The API you are calling is giving accurate JSON response sometimes and sometimes URL return 404 page saying sorry.

I looked through the reverse engineering process in _calculate_tk function and tried to change it, but I am not having any success.
I think, the only problem is with the google translate URL, where they might have added some Recaptcha or security parameter.

@sloria
Copy link
Owner

sloria commented Sep 14, 2021

I won't have time to look into this myself, but if someone sends a PR to fix this, I would merge it.

@vicru
Copy link

vicru commented Sep 15, 2021

Even though I I am using 0.15.3 (which is one version lower than the latest, which has been reported not to have the "translate" option in more), the translate option keeps returning a very similar error than the one above linked ("HTTP Error 404: Not Found").
@sloria's recent reply and this current issue, however, gives me hope that other versions of TextBlob might still translate?

@hinink
Copy link

hinink commented Sep 17, 2021

I won't have time to look into this myself, but if someone sends a PR to fix this, I would merge it.

I found that some parameters of the interface changed, and the format returned after the modification was different. In translate.py, the url was changed to
https://translate.googleapis.com/translate_a/t?anno=3&client=te&format=html&v=1.0&key&tc=1&sr=1&mode=1, you can try
Modify and add client=te&format=html

@yes-G
Copy link

yes-G commented Sep 17, 2021

I won't have time to look into this myself, but if someone sends a PR to fix this, I would merge it.

I found that some parameters of the interface changed, and the format returned after the modification was different. In translate.py, the url was changed to
https://translate.googleapis.com/translate_a/t?anno=3&client=te&format=html&v=1.0&key&tc=1&sr=1&mode=1, you can try
Modify and add client=te&format=html

Hey, I checked your suggestion for the new URL. after changing the URL the translate function no longer returns a 404. Don't know what other impacts it has. Do you suppose you will initiate a Pull Request with your fix?

@BZ2020
Copy link

BZ2020 commented Sep 19, 2021

@zc520yzy Thank you. That fixed that.

sudoguy added a commit to sudoguy/TextBlob that referenced this issue Sep 20, 2021
@hinink
Copy link

hinink commented Sep 20, 2021 via email

@AchuAswin28
Copy link

url not found error sometime:

File "/usr/local/lib/python3.8/dist-packages/textblob/blob.py", line 546, in translate
return self.class(self.translator.translate(self.raw,
File "/usr/local/lib/python3.8/dist-packages/textblob/translate.py", line 54, in translate
response = self.request(url, host=host, type=type_, data=data)
File "/usr/local/lib/python3.8/dist-packages/textblob/translate.py", line 92, in _request
resp = request.urlopen(req)
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Use Googletrans to translate the text

import googletrans
from googletrans import Translator

translater = Translator()
value = translater.translate(value)
print(value.src)

To detect the language we can use this...

#395

@mathieuchateau
Copy link

@sloria : would be great if you could merge & update PR :)

@Abdo-Saleh
Copy link

Linux batch:
sed -i '33s/url = .*/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"/' /path-to-your-local-python/site-packages/textblob/translate.py

Docker image (add this to your docker file):
RUN sed -i '33s/url = .*/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"/' /usr/local/lib/python3.10/site-packages/textblob/translate.py

@pdeitel
Copy link

pdeitel commented Oct 16, 2021

@sloria any updates on merging the fix?

@sloria sloria closed this as completed in c2ad49f Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests