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

Feature/enhance use of direct api #237

Conversation

alainrouillon
Copy link

In a perspective to help solving issue #234 I propose a solution that implements a proper way to use translate.googleapis.com as url service.
This url service has following characteristics:

  • no need for a token
  • uses client gtx instead of webapp
    I made a few modifications to mainly deal with these characteristics, preserving the possibility to use standard webapp calls.
    The client should use 'translate.googleapis.com' as service url when instanciating Translator() object, adapted code will manage the valuation of client gtx in utils params.
    Looking forward to reading your remarks for improvement is needed before final merge.

fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token
fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token
fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token
fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token
fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token
@ssut ssut self-requested a review November 13, 2020 16:58
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 91.727% when pulling 15b236f on alainrouillon:feature/enhance-use-of-direct-api into 4f7c079 on ssut:master.

@alainrouillon
Copy link
Author

I can see travis went through. If one look at the errors this is due to gtoken.py test which cannot stably work anymore as it is the origin of the problem !!! This means no pull request at all can be done, we seem to be in a deadlock.
Please have a look at the changes this PR proposes, which could solve so many disastreous prod situation.
Thanks a lot

@ssut
Copy link
Owner

ssut commented Nov 16, 2020

I'll take a look and consider remove that test if it doesn't work out.

@alainrouillon
Copy link
Author

I know you well know your job, no doubt, but just to mention here that the objective is to have a different way of working with the service url that adresses the api with the gtx client and no need for a token.
This service needs to be defined in the translator.
It is possible that this service can be less performant than the webapp which could have more updates (I honestly don't know).
My solution is a valuable workaround, but certainly not the ultimate solution which consists in reverse engineer the token valuation.
Thanks considering it ;-)

@mohamedniyaz1996
Copy link

When I ran the code, at times I am getting same error once in 3 tries

error in result (AttributeError: 'NoneType' object has no attribute 'group')

But actually it solved my other problem, from yesterday where I raised an issue that Output from translator is same as Input. Here is the reference to issue #246.

This code actually when it is not giving error , gives me proper output like before. Not sure , how it had fixed , will check the code and try to figure out.

Thanks to @alainrouillon for this.

@adkuln
Copy link

adkuln commented Nov 21, 2020

do you check it for multiple texts? I tried and get output the same as input after addition these fixes

@mohamedniyaz1996
Copy link

@adkuln I used proxy for each request , at times it shows same error like NoneType object has no attribute group but while giving output it is giving me proper translated output .

Anyways , I ll check for couple of days and will notify the situation.

@alainrouillon
Copy link
Author

do you check it for multiple texts? I tried and get output the same as input after addition these fixes

@adkuln : Hi, not sure I understand 'multiple texts'. For sure this fix aims to have similar behaviour as existing code, just uses a different end client to do the job.

@alainrouillon
Copy link
Author

@mohamedniyaz1996 : glad it helped. But I'm surprised to read you got into error as I ran 100+ tests without any problem.

@mohamedniyaz1996
Copy link

mohamedniyaz1996 commented Nov 24, 2020

@mohamedniyaz1996 : glad it helped. But I'm surprised to read you got into error as I ran 100+ tests without any problem.

@alainrouillon , I have been using within Translator object with proxies parameter which might have caused this issue, let me try without proxies and check.

@alainrouillon
Copy link
Author

@mohamedniyaz1996 : glad it helped. But I'm surprised to read you got into error as I ran 100+ tests without any problem.

@alainrouillon , I have been using within Translator object with proxies parameter which might have caused this issue, let me try without proxies and check.

@mohamedniyaz1996 : when creating Translator you have to define the service url as : translate.googleapis.com

@adkuln
Copy link

adkuln commented Nov 24, 2020

i tried with proxies and after N trials, i got not-translations, but original texts from api

@alainrouillon
Copy link
Author

i tried with proxies and after N trials, i got not-translations, but original texts from api

@adkuln: Hi, as I said to Mohamed, please refer right service url (translate.googleapis.com).
Can you please give me code snippet to reproduce or analyse your pb ?

@mohamedniyaz1996
Copy link

mohamedniyaz1996 commented Nov 24, 2020

@mohamedniyaz1996 : glad it helped. But I'm surprised to read you got into error as I ran 100+ tests without any problem.

@alainrouillon , I have been using within Translator object with proxies parameter which might have caused this issue, let me try without proxies and check.

@mohamedniyaz1996 : when creating Translator you have to define the service url as : translate.googleapis.com

Below provided the code-block

from googletrans import Translator
translator = Translator(service_urls=['translate.google.com'])
translated_text = translator.translate("सभी एक में अश्वशक्ति रंग लेजर प्रिंटर",dest="en")
print(translated_text.text) <----- This turns out to be सभी एक में अश्वशक्ति रंग लेजर प्रिंटर

If I make service_urls to be translate.googleapis.com it is not working and moreover I am seeing for all cases, I again starting to get same input as output. Please correct me if I am not using Translator() object in adherence.

@alainrouillon
Copy link
Author

@mohamedniyaz1996 : glad it helped. But I'm surprised to read you got into error as I ran 100+ tests without any problem.

@alainrouillon , I have been using within Translator object with proxies parameter which might have caused this issue, let me try without proxies and check.

@mohamedniyaz1996 : when creating Translator you have to define the service url as : translate.googleapis.com

Below provided the code-block

from googletrans import Translator
translator = Translator(service_urls=['translate.google.com'])
translated_text = translator.translate("सभी एक में अश्वशक्ति रंग लेजर प्रिंटर",dest="en")
print(translated_text.text) <----- This turns out to be सभी एक में अश्वशक्ति रंग लेजर प्रिंटर

If I make service_urls to be translate.googleapis.com it is not working and moreover I am seeing for all cases, I again starting to get same input as output. Please correct me if I am not using Translator() object in adherence.

Please ensure you have dowloaded the whole branch and replaced your local py-googletrans with this code. There are impacts to drive code execution properly considering the service url you choose. If translate.googleapis.com you don't use the same end client that does not required any token. Please ensure as well that your proxy allows to reach the endpoint.

@mohamedniyaz1996
Copy link

mohamedniyaz1996 commented Nov 24, 2020

@alainrouillon , Thanks for the suggestion, My local existing old googletrans didnt get replaced - Now it is working with no issues.

Let me test for 10-20 thousand small strings and will monitor if anything breaks.

For others, who are reading, I followed below steps to delete existing googletrans and replaced with new code from @alainrouillon :

  1. pip uninstall googletrans
  2. git clone https://github.com/alainrouillon/py-googletrans.git
  3. git checkout feature/enhance-use-of-direct-api
  4. python setup.py install

That's it! It works like a charm. To check if Updated code got installed, I executed below block:

from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com']) # At direct pip install,this service_url : translate.googleapis.com will not work , this is the indicator that new code had been installed
translated_text = translator.translate("सभी एक में अश्वशक्ति रंग लेजर प्रिंटर",dest="en")
print(translated_text.text)

Now, in-real it seems like solving the problem of #246.

Thanks @alainrouillon for this.

@fawazahmed0
Copy link

fawazahmed0 commented Nov 24, 2020

Thanks for your PR @alainrouillon , I have tested your PR it's working great, just in case someone it still having issue you can follow what @mohamedniyaz1996 wrote or can also do this way:

pip3 uninstall googletrans
pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api

And now the below code should work fine:

from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com']) # At direct pip install,this service_url : translate.googleapis.com will not work , this is the indicator that new code had been installed
translated_text = translator.translate("सभी एक में अश्वशक्ति रंग लेजर प्रिंटर",dest="en")
print(translated_text.text)

Update: 26-11-2020
Today I did the translation for few 100 times and then it started giving the output same as input as mentioned here

Anyone facing issue like what I faced, can try this

Thanks

@alainrouillon
Copy link
Author

@ssut
Hi, as by now this feature works and starts to be used spreadwide. Maybe it could be a huge benefit for the community if we could fix this travis test not working as obviously it can not work anymore. How do you want to proceed ?

@adkuln
Copy link

adkuln commented Dec 1, 2020

@alainrouillon , Thanks for the suggestion, My local existing old googletrans didnt get replaced - Now it is working with no issues.

Let me test for 10-20 thousand small strings and will monitor if anything breaks.

For others, who are reading, I followed below steps to delete existing googletrans and replaced with new code from @alainrouillon :

  1. pip uninstall googletrans
  2. git clone https://github.com/alainrouillon/py-googletrans.git
  3. git checkout feature/enhance-use-of-direct-api
  4. python setup.py install

That's it! It works like a charm. To check if Updated code got installed, I executed below block:

from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com']) # At direct pip install,this service_url : translate.googleapis.com will not work , this is the indicator that new code had been installed
translated_text = translator.translate("सभी एक में अश्वशक्ति रंग लेजर प्रिंटर",dest="en")
print(translated_text.text)

Now, in-real it seems like solving the problem of #246.

Thanks @alainrouillon for this.

Hi, i repeat your steps for 700 steps:
After 250 steps I started get original text, not translation

@ssut
Copy link
Owner

ssut commented Dec 1, 2020

@ssut
Hi, as by now this feature works and starts to be used spreadwide. Maybe it could be a huge benefit for the community if we could fix this travis test not working as obviously it can not work anymore. How do you want to proceed ?

I still debate on whether releasing this to PyPI is enough because this is a temporary workaround that can't help everyone suffering the same issue.
All I can say now and suggest at this point is: what do you think about releasing this as a beta for now?

@alainrouillon
Copy link
Author

@ssut
Hi, as by now this feature works and starts to be used spreadwide. Maybe it could be a huge benefit for the community if we could fix this travis test not working as obviously it can not work anymore. How do you want to proceed ?

I still debate on whether releasing this to PyPI is enough because this is a temporary workaround that can't help everyone suffering the same issue.
All I can say now and suggest at this point is: what do you think about releasing this as a beta for now?

Yes we can try this

@ssut
Copy link
Owner

ssut commented Dec 1, 2020

@ssut
Hi, as by now this feature works and starts to be used spreadwide. Maybe it could be a huge benefit for the community if we could fix this travis test not working as obviously it can not work anymore. How do you want to proceed ?

I still debate on whether releasing this to PyPI is enough because this is a temporary workaround that can't help everyone suffering the same issue.
All I can say now and suggest at this point is: what do you think about releasing this as a beta for now?

Yes we can try this

I will try to do that tomorrow night (GMT+9 here.)

@RodjerWilko
Copy link

Good afternoon, What's wrong with the googletrans library? When calling the .translate function, an error occurs

@mohamedniyaz1996
Copy link

@alainrouillon , Thanks for the suggestion, My local existing old googletrans didnt get replaced - Now it is working with no issues.
Let me test for 10-20 thousand small strings and will monitor if anything breaks.
For others, who are reading, I followed below steps to delete existing googletrans and replaced with new code from @alainrouillon :

  1. pip uninstall googletrans
  2. git clone https://github.com/alainrouillon/py-googletrans.git
  3. git checkout feature/enhance-use-of-direct-api
  4. python setup.py install

That's it! It works like a charm. To check if Updated code got installed, I executed below block:

from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com']) # At direct pip install,this service_url : translate.googleapis.com will not work , this is the indicator that new code had been installed
translated_text = translator.translate("सभी एक में अश्वशक्ति रंग लेजर प्रिंटर",dest="en")
print(translated_text.text)

Now, in-real it seems like solving the problem of #246.
Thanks @alainrouillon for this.

Hi, i repeat your steps for 700 steps:
After 250 steps I started get original text, not translation

Please note that I used proxies to avoid such bottle-neck cases.

@RodjerWilko
Copy link

All the same, the same does not work, can I somehow do it wrong on the server?

@wibor
Copy link

wibor commented Dec 2, 2020

Hi, there is something still wrong in gtoken.py:
in function _update() in line 54 r = self.client.get(self.host), but str(r) ==<Response [404 Not Found]>
and later I get error:
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

@ssut ssut changed the base branch from master to feature/temp-fix-for-missing-tkk-tokens December 2, 2020 13:13
@ssut ssut merged commit 533a651 into ssut:feature/temp-fix-for-missing-tkk-tokens Dec 2, 2020
@alainrouillon
Copy link
Author

Hi, there is something still wrong in gtoken.py:
in function _update() in line 54 r = self.client.get(self.host), but str(r) ==<Response [404 Not Found]>
and later I get error:
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

Sure the gtoken function cannot work anymore the way it was. If one still uses service url to point to usual translate.googletrans.xxx it will not work. This feature is a fix to be able to use safely another service url to point to a different end client, without any token.

@ssut
Copy link
Owner

ssut commented Dec 2, 2020

🎉 New Alpha Version Release

I've released googletrans@3.1.0a0 on PyPI and it seems to be working. Note that you all have to specify the package version like: pip install googletrans==3.1.0a0.

@alainrouillon
Copy link
Author

🎉 New Alpha Version Release

I've released googletrans@3.1.0a0 on PyPI and it seems to be working. Note that you all have to specify the package version like: pip install googletrans==3.1.0a0.

Thank you Suhun. Hope people have good use of it and got the fact they have to use a specific service url.
Have a nice day !

@Hemanthkumar2112
Copy link

hi i have used many method to over come this issue but result is negative , then i searched many and finally got this https://github.com/lushan88a/google_trans_new

this post may useful for you guys

@wajdyz
Copy link

wajdyz commented Dec 3, 2020

Now it has stopped sending back translated text, it returns the original only.

@santos-gabriel-dario
Copy link

Something that may be useful is to use a VPN while the program is running (I'm using the googletrans alpha version). That way it starts translating to the "dest" language again.
Hope it helps you guys!

@gelodefaultbrain
Copy link

gelodefaultbrain commented Dec 8, 2020

Hello! I have put a new issue please refer here! Thank you guys! you guys are AWESOME!

Translation result returns the same text

@ezgisubasi
Copy link

Hello, I do not get any errors but my code does not translate either. It was translating at first, now it is not doing anymore, what should I do?

@Maerecque
Copy link

I used the git clone command with the given branch, and for me the api actually translates and works fine. I uninstalled it and reinstalled it multiple times and it keeps working fine for me, I'm using Python 3.7.x, maybe that does something with it

@ezgisubasi
Copy link

AttributeError: 'NoneType' object has no attribute 'translate'

Why I get this error?

@ezgisubasi
Copy link

AttributeError: 'NoneType' object has no attribute 'translate'

Why I get this error?

Okay, when I use 3.9 I get this error. If I down to 3.7 I get AttributeError: 'NoneType' object has no attribute 'group' error, it was worked fine yesterday I don't understand why it is not working again.

The code I tried is:

from googletrans import Translator

translator = Translator(service_urls=['translate.googleapis.com']) # At direct pip install,this service_url : translate.googleapis.com will not work , this is the indicator that new code had been installed
translated_text = translator.translate("cat", dest="tr")
print(translated_text.text)

Also, the people who suggest google_trans_new it does not work as well.

@JosXa
Copy link

JosXa commented Dec 20, 2020

>>> tr.translate(["hallo", "freunde"], dest='en')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/ivtranslator/.venv/lib/python3.8/site-packages/googletrans/client.py", line 219, in translate
    parsed = json.loads(data[0][2])
  File "/usr/local/lib/python3.8/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

Looks like with the rc-1 version the multiple-inputs use case is indeed broken?

Not sure if this is part of a release already, or already fixed.

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

Successfully merging this pull request may close these issues.

None yet