Closed mannan291 closed 2 years ago
I am having the same issue. it worked a week ago, now I'm receiving a 404 error whenever I call detect_language()
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.
I won't have time to look into this myself, but if someone sends a PR to fix this, I would merge it.
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?
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
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?
@zc520yzy Thank you. That fixed that.
I suggest using the above URL directly, but this will affect the current business. Because the returned data has changed, the above URL is feasible. I have tested it
---Original--- From: @.> Date: 2021/9/20 07:08:00 To: @.>; Cc: @.**@.>; Subject: Re: [sloria/TextBlob] error intranslation (#395)
@zc520yzy Thank you. That fixed that.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
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...
@sloria : would be great if you could merge & update PR :)
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
@sloria any updates on merging the fix?
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