-
Notifications
You must be signed in to change notification settings - Fork 706
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
Add handling for when TKK is already rendered #78
Conversation
Coverage decreased most likely because the exception case will only be exercised about 5% of the time. |
Here is another version of the fix, it is a bit cleaner:
Edit: Removed |
@Darkblader24 Yes much cleaner, updated using your solution. |
It worked for me. Thank you very much. |
This will cause |
Oh, I forgot to remove this for this post.
|
@Darkblader24 after applying your solution i got below error..
ValueError: No JSON object could be decoded |
@hrishikeshpatel that appears unrelated to these changes. I can't find that code block in the library. |
But i got this type of error only after making these changes.. ValueError Traceback (most recent call last) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/client.pyc in translate(self, text, dest, src) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/client.pyc in _translate(self, text, dest, src) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/utils.pyc in format_json(original) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/site-packages/googletrans/utils.pyc in legacy_format_json(original) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/json/init.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/json/decoder.pyc in decode(self, s, _w) /home/hrishikesh/anaconda3/envs/MTP_IITM/lib/python2.7/json/decoder.pyc in raw_decode(self, s, idx) ValueError: No JSON object could be decoded |
I can confirm that I have the same error as @hrishikeshpatel . It appeared after I applied @Darkblader24 's changes. |
After applying @Darkblader24's fix, I'm also receiving the json error from |
Here is r.text after using the fix listed here. Looks like its returning a 403: <!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 403 (Forbidden)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>403.</b> <ins>That’s an error.</ins>
<p>Your client does not have permission to get URL <code>/translate_a/single?client=t&sl=auto&tl=en&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&tk=684737.684737&q=test</code> from this server. <ins>That’s all we know.</ins> |
Yes. Same for me. Response 403 from google, Tried it at server that couldn't be banned. |
It works perfectly fine for me. Maybe this is somehow regional? |
I live in EU and I tried a VPN from USA to check if this regional. But I've encountered this in both cases. My script that uses this library is able to translate a couple of characters, but then it starts to fail with this JSON error. Is it possible that somehow it fails to renegotiate the token or something? I get it now. You see the JSON error when you use google translate too much and it refuses to translate more. It tells you that there was too much traffic from your IP address an you should try again later. Do you have any way to bypass that? |
If it's restricting by ip, there's no way to bypass it other than cycle ips. Do you know what the limit is? |
I've saturated my IP address after about 14k characters. |
For those getting a 403, you'll see the same issue if you use curl (curl -A GET https://translate.google.com). There's most likely a limit being placed by Google when making multiple queries from the same IP. Keep in mind that the Google Translate API is a paid service now: https://cloud.google.com/translate/pricing |
Yeah, after applying this fix, it seems to work fine for me. I know that #47 is also related to getting a 403 when using certain emojis (which causes it to generate the wrong token). I applied this PR as a workaround and it seemed to fix that for me too. Not sure if that's the cause of the 403's people are getting here, but maybe it's worth looking into. |
where canI find this file to make this change? |
work for me too . tnx |
@asanchez126
It can be reproduced on my environment when original text to be translated has more than 5,000 characters. I don`t know why it happens, but I solved this problem by separating every 5,000 characters and translating each of them. |
hey folks, any updates on when this is going to be merged? |
Haven't heard from the repo owner, not sure that it will get merged. I've been using the fork, we may need to completely fork it and publish to Pypi. |
@Guy-Dipietro-Bose please consider claiming ownership on pipy |
@Guy-Dipietro-Bose please make a fork :) |
Until this is released, you can also install the code of this PR over git: pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade |
@loopdigga98 How much delay did you put between each query ? My IP is blocked by Google. How can I unblock it ? |
The only thing to do is wait. You should be able to use it after ca. 24 hours. I'm using 1 second delay between queries and it works for me. |
much easier solution ! |
@umairqadir97 Did that work for you? I've tried that earlier today and got |
@boing102 yes it's working for me. This is something i'm trying with it:
|
I've tried both detect() and translate() functions, both yielding the same error. Also in the brand new venv, guess I just have to wait. |
@boing102 Have you installed it from above mentioned git Repo? Can you sendyour snippet plus error it's showing ? |
@umairqadir97 Yep, I used that repo to install. |
In my opinion, Google may block web api that py-googletrans uses. In detail, I made a curl call for that url. Response was that google blocks invalid request. Although I have figured out the cause, but there is no solution. = Logging for py-googletrans
= Curl call
|
@tgi01054 Goslate is working for me at the time of writing. EDIT: |
Worked for me Request returnes new format of tkk field in response page
|
I close this pull request now that I have merged #95. |
I try to make a translator and this error comes. |
@1998Suraj I suspect you made a typo: |
Randomly the TKK value is coming back already rendered. This will handle that case.