ssut / py-googletrans

(unofficial) Googletrans: Free and Unlimited Google translate API for Python. Translates totally free of charge.
http://py-googletrans.rtfd.io
MIT License
3.93k stars 724 forks source link

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

Open Mohammadwh opened 4 years ago

Mohammadwh commented 4 years ago

hi i use Python 3.6.9 and when i call translate have this error: image

ssut commented 3 years ago

@ZacharyZQ Did you set the service_urls manually?

Keerat666 commented 3 years ago

Just tried https://github.com/lushan88a/google_trans_new Works for me.

I switched to this and it works fine even in Google Collab!

elsatmirdes commented 3 years ago

Sadece https://github.com/lushan88a/google_trans_new Works'ü denedim .

Buna geçtim ve Google Collab'de bile iyi çalışıyor!

friends workeddd !!!!!!. I hope this works everybody I am from Turkeyy

lidiasm commented 3 years ago

Just tried https://github.com/lushan88a/google_trans_new Works for me.

Best library ever!! Thank you!!!

dravicenna commented 3 years ago

Just tried https://github.com/lushan88a/google_trans_new Works for me.

Had the same problem in Spain. This library solved it. Thanx!

tuanhoang97 commented 3 years ago

🎉 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. And you don't have to set service_urls manually as I've set it as translate.googleapis.com by default.

have some issue, it not translate :(, i come from viet nam image

alainrouillon commented 3 years ago

🎉 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. And you don't have to set service_urls manually as I've set it as translate.googleapis.com by default.

I was involved in the PR for this release. What I can say is that we try to bring a solution to a problem that suddenly appeared and brought the community in a bad position.

I could see some of you being early adopters of the feature. It solved the situation for some and did not for some. We decided to release the feature as we could help the community in some extend.

On top of this lushan88a proposed another release that could help for some, but not for the some (my case !).

What I am trying to say is :

All in all this alpha release is a step to move from a stated 0% working lib to a > 0% working lib. Each one has to test it and adopt or not, and is free of course to try lushan88a lib that also seems to help in this way.

Have all a great day and great time by this diffcult period !

bhavnakumari commented 3 years ago

I upgraded httpx to the latest version (in spite of pip complaining it's not compatible with py-googletrans), and the stability seems to be back to how it was before... Could be a coincidence though.

Worked for me. Quite interestingly, changing the service URL to translate.google.com worked on my PC but not on my Linux server. However, there upgrading httpx seems to have temporarily fixed it. :)

can you tell me how did you do it...how to upgrade httpx and change the url?

rsiw2000 commented 3 years ago

🎉 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. And you don't have to set service_urls manually as I've set it as translate.googleapis.com by default.

have some issue, it not translate :(, i come from viet nam image

Hello. I having same error issue at TKK regular expression.

I'd test @alainrouillon 's solution from github last night and today I'm testing googtrans 3.1.0a0.

Both worked for a while, but starts respondind with "non-translated" original text.

image

This server is at Amazon in USA.

joshenders commented 3 years ago

FWIW this npm library may have a trick for generating the token: https://www.npmjs.com/package/translate-google

luckrill commented 3 years ago

aws ec2 debian

Python 3.7.9 (default, Aug 27 2020, 21:59:41) [GCC 7.3.1 20180712 (Red Hat 7.3.1-9)] on linux Type "help", "copyright", "credits" or "license" for more information.

from googletrans import Translator translator = Translator() translator.translate("hello") Traceback (most recent call last): File "", line 1, in File "/home/ec2-user/.local/lib/python3.7/site-packages/googletrans/client.py", line 182, in translate data = self._translate(text, dest, src, kwargs) File "/home/ec2-user/.local/lib/python3.7/site-packages/googletrans/client.py", line 78, in _translate token = self.token_acquirer.do(text) File "/home/ec2-user/.local/lib/python3.7/site-packages/googletrans/gtoken.py", line 194, in do self._update() File "/home/ec2-user/.local/lib/python3.7/site-packages/googletrans/gtoken.py", line 62, in _update code = self.RE_TKK.search(r.text).group(1).replace('var ', '') AttributeError: 'NoneType' object has no attribute 'group'

MachadoLhes commented 3 years ago

:tada: 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. And you don't have to set service_urls manually as I've set it as translate.googleapis.com by default.

Tested it with my application and it's working perfectly! My app is deployed in Heroku (US Region) and it's running well after I specified the googletrans@3.1.0a0 version on the project's requirements.txt file. Thanks for the solution!

kv-y commented 3 years ago

googletrans@3.1.0a0 python 3.8.3 Hetzner server

It doesn't translate anything. "HTTP/2 429 Too Many Requests" in log.

Mat37 commented 3 years ago

googletrans@3.1.0a0 python 3.8.3 Hetzner server

It doesn't translate anything. "HTTP/2 429 Too Many Requests" in log.

How do you see the log ? I think i have same issue.

kv-y commented 3 years ago

How do you see the log ? I think i have same issue.

from googletrans import Translator
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

t = Translator()
res = t.translate('Тестовый текст', dest='en').text
print(res)

Now it's working correct:

"HTTP/2 200 OK"
Test text

I will try to find out when it changes to Too Many Requests error.

Mat37 commented 3 years ago

How do you see the log ? I think i have same issue.

from googletrans import Translator
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

t = Translator()
res = t.translate('Тестовый текст', dest='en').text
print(res)

Now it's working correct:

"HTTP/2 200 OK"
Test text

I will try to find out when it changes to Too Many Requests error.

I was able to do one translation (i made a python obfuscator and it translates a text 35 times), which is in reality 35, and when i tried again with another text, i got error 429. Previously i was able to "translate" an entire game this way without any problems.

fsan commented 3 years ago

version googletrans@3.1.0a0 worked well for me at first

but after some time

EDITING File "C:\Users\pabyo\myenv\lib\site-packages\googletrans\client.py", line 184, in translate src = src.lower().split('_', 1)[0] AttributeError: 'list' object has no attribute 'lower'

cherwoshliapp commented 3 years ago

https://github.com/lushan88a/google_trans_new

This package also worked for me! Many thanks!!!

rjtmehta99 commented 3 years ago

googletrans@3.1.0a0 python 3.8.3 Hetzner server

It doesn't translate anything. "HTTP/2 429 Too Many Requests" in log.

Facing the same issue. Can anyone comment if the same error occurs with https://github.com/lushan88a/google_trans_new? Also, is the "Too Many Requests" issue resolved after a specific time period?

Mat37 commented 3 years ago

googletrans@3.1.0a0 python 3.8.3 Hetzner server It doesn't translate anything. "HTTP/2 429 Too Many Requests" in log.

Facing the same issue. Can anyone comment if the same error occurs with https://github.com/lushan88a/google_trans_new? Also, is the "Too Many Requests" issue resolved after a specific time period?

I was able to do ~350 translations without any problem with the new package, with the other package i got 429 after not even 100 so i'd say this is working

ezgisubasi commented 3 years ago

Hi, I have an error like raise ProtocolError(event) httpcore._exceptions.ProtocolError: <ConnectionTerminated error_code:ErrorCodes.COMPRESSION_ERROR, last_stream_id:1, additional_data:687061636b5f76616c

I guess it's a timeout issue (since it says timeout for each attribute), how can I solve this timeout problem?

elsatmirdes commented 3 years ago

@ezgisubasi googlr_trans_new adlı kütüphaneyi kullanabilirsin sorunsuz çalışıyor. Buralarda türkleri görmek sevindirdi :)

ashishalakhani commented 3 years ago

🎉 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. And you don't have to set service_urls manually as I've set it as translate.googleapis.com by default.

what caused this error in first place? What will prevent it from not happening again? Are there certain limitations on this package? like 300 request / day or something that we need to take into account?

How is this library different from https://github.com/lushan88a/google_trans_new

please advice!

wongzy commented 3 years ago

image googletrans-2.3.0-py3.8.egg. This issue still exists...Can you provide any way to fix this problem? I tried lots of way on the network, but none of them worked...

ssut commented 3 years ago

:tada: New Alpha Version Release (Stable Release Candidate): 4.0.0-rc1

I've released a new alpha version of Googletrans that uses Google's new RPC-based translate mechanism. Please track this on #255, and test out the new package.

ssut commented 3 years ago

image googletrans-2.3.0-py3.8.egg. This issue still exists...Can you provide any way to fix this problem? I tried lots of way on the network, but none of them worked...

@wongzy Please check the comment above and try using pip install googletrans==4.0.0-rc1.

sb-premiere commented 3 years ago

Thanks, it appears this version has not propaged to conda channels.

End up cloning conda environment and running this command.

pip install googletrans==4.0.0-rc1 --upgrade-strategy only-if-needed

Tros-t commented 3 years ago

I dont understand what should I do What changes should I make at gtoken.py

I am a beginner for googletrans

sb-premiere commented 3 years ago

I dont understand what should I do What changes should I make at gtoken.py

I am a beginner for googletrans

Do nothing, this issue is fixed as mentioned above https://pypi.org/project/googletrans/4.0.0rc1/. Install this version+, everything should work as expected.

Tros-t commented 3 years ago

which version

sb-premiere commented 3 years ago

I'm also new to googletrans. Take time to read the messages on the thread. At least couple of times the command is shared.

pip install googletrans==4.0.0-rc1

Tros-t commented 3 years ago

Sorry LOL I was frustrated

wongzy commented 3 years ago

pip install googletrans==4.0.0-rc1

Thanks, it worked~

hiyamgh commented 3 years ago

I'm also new to googletrans. Take time to read the messages on the thread. At least couple of times the command is shared.

pip install googletrans==4.0.0-rc1

This worked for me as well, it feels nice when you fix a problem in 2020 :)

ssut commented 3 years ago

I'm also new to googletrans. Take time to read the messages on the thread. At least couple of times the command is shared. pip install googletrans==4.0.0-rc1

This worked for me as well, it feels nice when you fix a problem in 2020 :)

I will try to get it stable in 2020. Thank you!

mirfan899 commented 3 years ago

Thanks, it appears this version has not propaged to conda channels.

End up cloning conda environment and running this command.

pip install googletrans==4.0.0-rc1 --upgrade-strategy only-if-needed

It worked for me.

rcv911 commented 3 years ago

Hi.

OS: Ubuntu 18.04.5 LTS Python 3.7 httpx==0.16.1 googletrans==4.0.0-rc1

from googletrans import Translator tr = Translator() tr.translate('test')

<googletrans.models.Translated object at 0x7ff7e47ac7d0>

I'm not sure it's a good way to show this answer, anyway I can use magic method.

eltallerdetd commented 3 years ago

Just tried pip install googletrans==4.0.0-rc1 but it does not change anything. I've just the following code

from googletrans import Translator

translator = Translator()

print(translator.detect('hola'))

and the error keeps being the same AttributeError: 'NoneType' object has no attribute 'group'

Just wanna post to let @ssut know!

-Tad

caffeinetoomuch commented 3 years ago

One issue with googletrans==4.0.0-rc1:

When it is given multiple sentences at once in one request, space after each sentence is removed!

ezgisubasi commented 3 years ago

when I use 3.9 I get AttributeError: 'NoneType' object has no attribute 'translate' 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.

elsatmirdes commented 3 years ago

from google_trans_new import google_translator

translator = google_translator()

text = "Bugün hava yağmurlu"

print(translator.translate(text))

Nasıl çalışmadı yeni denedim hala çalışıyor.

Yukardaki kodu kütüphaneyi silip bidaha yükleyerek deneyebilirmisin.

mohamedniyaz1996 commented 3 years ago

when I use 3.9 I get AttributeError: 'NoneType' object has no attribute 'translate' 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.

service_urls parameter value should not be translate.googleapis.com at googletrans-4.0.0rc1, remove that complete argument and check, Else below block can be tried:

translator = Translator(service_urls=['translate.google.com','translate.google.co.kr'])
translated_text = translator.translate("cat", dest="tr")
print(translated_text.text)
mohamedniyaz1996 commented 3 years ago

from google_trans_new import google_translator

translator = google_translator()

text = "Bugün hava yağmurlu"

print(translator.translate(text))

Nasıl çalışmadı yeni denedim hala çalışıyor.

Yukardaki kodu kütüphaneyi silip bidaha yükleyerek deneyebilirmisin.

google trans 4.0.0rc1 çoğu zaman iyi çalışıyor ve çok iyi bir topluluğa sahip - ancak google_trans_new bir arada da kullanılabilir

aquamarine5 commented 3 years ago

I'm also new to googletrans. Take time to read the messages on the thread. At least couple of times the command is shared.

pip install googletrans==4.0.0-rc1

Thanks !

jxxxy commented 3 years ago

As mohamedniyaz1996 commented, the following way can work

from google_trans_new import google_translator translator = google_translator() text=" Bugün hava yağmurlu" translator.translate(text)

ps. "Bugün hava yağmurlu" = "The weather is rainy today", right?

elsatmirdes commented 3 years ago

@jxxxy right, this library "google_trans_new" successfully running

perymerdeka commented 3 years ago

I'm also new to googletrans. Take time to read the messages on the thread. At least couple of times the command is shared.

pip install googletrans==4.0.0-rc1

thanks it work for me

perymerdeka commented 3 years ago

As mohamedniyaz1996 commented, the following way can work

from google_trans_new import google_translator translator = google_translator() text=" Bugün hava yağmurlu" translator.translate(text)

ps. "Bugün hava yağmurlu" = "The weather is rainy today", right?

is it the same module like googletrans..?

perymerdeka commented 3 years ago

from google_trans_new import google_translator

translator = google_translator()

text = "Bugün hava yağmurlu"

print(translator.translate(text))

Nasıl çalışmadı yeni denedim hala çalışıyor.

Yukardaki kodu kütüphaneyi silip bidaha yükleyerek deneyebilirmisin.

what module are you using @jxxxy i use googletrans==4.0.0-rc1 i got this error

  File "/media/pery/pery_data/PycharmProjects/PengangguranExpert/sebelasjari-bot/venv/lib/python3.8/site-packages/googletrans/client.py", line 219, in translate
    parsed = json.loads(data[0][2])
  File "/usr/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

whereas yesterday worked well :(

NawtJ0sh commented 3 years ago

Will it only work with Python 3 now ?