Open Mohammadwh opened 4 years ago
Started facing it recently, like a week ago, very popular ISP in France
This problem occurs if you create a Translator instance for each use of the request. This problem can be partially avoided by using only one instance of the class.
It works for me. I got this error since I re-run my program several times. But not, it is working very well if I do not re-run my program frequently. Thx mate!!!
This problem occurs if you create a Translator instance for each use of the request. This problem can be partially avoided by using only one instance of the class.
It works for me. I got this error since I re-run my program several times. But not, it is working very well if I do not re-run my program frequently. Thx mate!!!
You will still face this issue but less frequent
Over at https://github.com/pndurette/gTTS they are wrestling with the same issues. I noticed that they are relying on https://github.com/Boudewijn26/gTTS-token to generate the token. This library has just been updated to retry the connection a few times.
py-googletrans has its own implementation of the token logic. I might be a good idea to also use gTTS-token, so that there is no duplication of effort in trying to reverse engineer the new changes Google made.
Same issue here. Hope it will be fixed soon :)
Interestingly, the while True:
approach results in an endless loop for me :(
Small update: the gTTS-token/gTTS people have reverse engineered the new API:
https://github.com/Boudewijn26/gTTS-token/blob/master/docs/november-2020-translate-changes.md
So, the hard work seems to be done, and the only thing left is doing something similar for py-googletrans
This problem occurs if you create a Translator instance for each use of the request. This problem can be partially avoided by using only one instance of the class.
Thank you @VOINTENT. Using one instance (instantiation outside the function) has just fixed the issue!
@Mohammadwh 's getTranslate()
works for very short phrases. I got about 50 disease names done rapidly.
Also, setting the particular translate such as translate.google.ca
etc was what I did. Anything longer though, ie. cells from a dataframe where one column is disease description, it stopped at 12% complete using tqdm progress bar.
I've written an annotated gist that uses the new Translate API, based on the content posted by @pbienst earlier. Though gTTS focuses on the TTS part, so I had to put some work into finding the right endpoint for translation and reverse engineering what I could of the results.
I don't actually use this library (I'm more familiar with the API side, and only what I actually need) and so I'm not familiar with all the internals. Whoever is maintaining this can feel free to reference my code.
@Roadcrosser thank you, this solution generally works well, but after multiple translations it gives the following error:
Traceback (most recent call last):
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 426, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\Raffaele\anaconda3\lib\http\client.py", line 1347, in getresponse
response.begin()
File "C:\Users\Raffaele\anaconda3\lib\http\client.py", line 307, in begin
version, status, reason = self._read_status()
File "C:\Users\Raffaele\anaconda3\lib\http\client.py", line 276, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Raffaele\anaconda3\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\util\retry.py", line 410, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 426, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\Raffaele\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\Raffaele\anaconda3\lib\http\client.py", line 1347, in getresponse
response.begin()
File "C:\Users\Raffaele\anaconda3\lib\http\client.py", line 307, in begin
version, status, reason = self._read_status()
File "C:\Users\Raffaele\anaconda3\lib\http\client.py", line 276, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
@raffaem I'm not sure, it could be a network error or you are being ratelimited.
I would also recommend commenting on the gist itself, as this thread is meant for the library and not my gist.
Production impacted by this issue. Any idea on when a fix will be pushed ?
Are there any tested workarounds until then ?
(Since I see it might be related to ISPs as well, the majority of our clients are located in Cyprus.)
Production impacted by this issue. Any idea on when a fix will be pushed ?
Are there any tested workarounds until then ?
(Since I see it might be related to ISPs as well, the majority of our clients are located in Cyprus.)
@waelmas Did u find any other good workaround meanwhile , if yes , please let me know
I used a VPN, and it did solve the issue. It seems its not the ISP, its the IDS/IPS settings on Google side is the issue.
I have been trying to make use of Googletrans and I am facing the 'Nonetype error'. Is there a way to work around this or has there been a fix?. I observed that the first run is successful on Jupyter notebook/Google colab, after that, the error emerges.
I have been trying to make use of Googletrans and I am facing the 'Nonetype error'. Is there a way to work around this or has there been a fix?. I observed that the first run is successful on Jupyter notebook/Google colab, after that, the error emerges.
I ended up using the official Google Cloud Translation API. It works perfectly. You pay as you consume. Check it out: https://cloud.google.com/translate
Also there seems be a new python package for google translate API by @lushan88a at here , I tested it, it's seems to be working fine
Also there seems be a new python package for google translate API by @lushan88a at here , I tested it, it's seems to be working fine
Issue solved! Thanks
Using it over a VPN, it has failed for me for servers in multiple countries over UDP. I'd rather not say specifics as to which ones. I added in try/except loop that makes it try a random new proxy if a query fails, but even so I can't seem to escape these failures. It works for a seemingly-random number of queries before failing (nowhere near 300, probably ~20 at the most). Using Ubuntu 20.04, Python 3.8.3, googletrans 3.0.0.
Same me. Without vpn the error happen, then try with vpn (protonVPN) and goes ok the first 300-400 translations, after this, the same error. I try to change to other vpn network servers but the error occurs very fast again, after 3 or 4 translation.
I use googletrans for a discord bot, (I'm not that great of a programmer) and I have a translate command where it takes in the language and then the phrase to translate, but only some languages work on my computer where I coded the bot (RPI 4 4gb RAM, running Raspbian 10), and when I put it on my server (RPI 3 B, running Raspbian 10), it doesn't work at all. Not sure, if it's something to do with my code, but hopefully this can be fixed soon. ISP: Wide Open West, Py version: 3.7.3, translate.google.com works fine on both machines.
This problem occurs if you create a Translator instance for each use of the request. This problem can be partially avoided by using only one instance of the class.
Thought that I was blocked due to my script running on a DigitalOcean droplet, but doing this seemed to make it work reliably.
You can overcome this issue by using error handling like so:
while True:
try:
# you translation code here
except:
print(Exception)
continue
break
Note that you have to include the initialization of translator object in try block since the API token is causing the problem and we have to re-generate it by reinitialize translator.
Edit: This no longer works.
Google has completely changed his Google Translate Ajax API, so it seems that the project can only be rewritten based on the new Google Translate Ajax API 😑
You can overcome this issue by using error handling like so:
while True: try: # you translation code here except: print(Exception) continue break
Note that you have to include the initialization of translator object in try block since the API token is causing the problem and we have to re-generate it by reinitialize translator.
This doesn't work, instead it just spams requests and the same exception over and over and will probably get you rate limited.
Today always this issue " AttributeError: 'NoneType' object has no attribute 'group'", I think Google translate will leaving in future, Please don't
Also there seems be a new python package for google translate API by @lushan88a at here , I tested it, it's seems to be working fine
Solve, thank you !
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
Does not work for someone from Spain.
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
The solution by @alainrouillon works for me.
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
The solution by @alainrouillon works for me.
The solution doesn't work from UK
Tried @alainrouillon solution with googleapis, both single and batch translate, it didnt work for me. Actually, using the original library works once in a while Saudi Arabia
The solution provided by @alainrouillon worked for me. Thanks!
The solution provided by @alainrouillon also worked for me.
translator = Translator(service_urls=['translate.googleapis.com'])
Did not work for me as well. I am using it in India!
The solution provided by @alainrouillon also worked for me.
Which country are you in?
I tested in Brazil.
Just tried https://github.com/lushan88a/google_trans_new Works for me.
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
This worked for me. Thanks!
EDIT: In SF Bay Area, United States
i still get the error AttributeError: 'NoneType' object has no attribute 'group' even when i try using translator = Translator(service_urls=['translate.googleapis.com']) i have test with
from googletrans import Translator translator = Translator(service_urls=['translate.googleapis.com']) translator.translate('hello') hmm, wait for the solution
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
The solution works for me from Japan. Thank you!
I submitted a PR about 2 weeks ago, that is awaiting for a validation, but that is already adopted by some. It uses url service translate.googleapis.com that requires to manage a different end client (code modifications to manage this). You can pull it this way : pip3 uninstall googletrans pip3 install git+https://github.com/alainrouillon/py-googletrans@feature/enhance-use-of-direct-api
I tried your stuff but it did not work :(
@dangmanhtruong1995 : you have to use translate.googleapis.com as url service in the instanciation of your translator object
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
Also works for me from South Korea! Thanks 👍
translator = Translator(service_urls=['translate.googleapis.com'])
Did not work for me as well. I am using it in India!
I too used it from India, still it works for me, Is that repo being installed properly?
i still get the error AttributeError: 'NoneType' object has no attribute 'group' even when i try using translator = Translator(service_urls=['translate.googleapis.com']) i have test with
from googletrans import Translator translator = Translator(service_urls=['translate.googleapis.com']) translator.translate('hello') hmm, wait for the solution
@tuanhoang97 : You have to install the feature as mentionned in other threads. Sure if you do so and set service_url to translate.googleapis.com that you can't go through this error. The use of this sevice_urls does not run through code that uses webapi end client and requires a token as for other service urls. Have a look to control you did actually installed the feature. Please note that the feature is under review and should be promoted as beta version soon.
@keerat666 and @tuanhoang97 I followed below steps to delete existing googletrans and replaced with new code from @alainrouillon - Please try this approach , it will work :
pip uninstall googletrans
git clone https://github.com/alainrouillon/py-googletrans.git
git checkout feature/enhance-use-of-direct-api
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)
@Keerat666 and @tuanhoang97 I followed below steps to delete existing googletrans and replaced with new code from @alainrouillon - Please try this approach , it will work :
pip uninstall googletrans git clone https://github.com/alainrouillon/py-googletrans.git git checkout feature/enhance-use-of-direct-api 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)
it work at the first time, but when i t try again, it not work, check my terminal text https://ideone.com/2CzFwf
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.
version is 3.1.0a0
hi i use Python 3.6.9 and when i call translate have this error: