Python googletrans attributeerror nonetype object has no attribute group

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

AttributeError: ‘NoneType’ object has no attribute ‘group’ #366

AttributeError: ‘NoneType’ object has no attribute ‘group’ #366

Comments

from googletrans import Translator # translator = Translator(service_urls=[ # 'translate.google.com', # ]) translator = Translator() data = str(open('first-post.md', encoding='utf8', newline='\n').read()) # print(data) translations = translator.translate([data], src='en', dest='fa') print(translations) print(translations._response.http_version) for translation in translations: print(translation.origin, ' -> ', translation.text) 
C:\Users\Max\Desktop>python translate.py Traceback (most recent call last): File "C:\Users\Max\Desktop\translate.py", line 10, in translations = translator.translate([data], src='en', dest='fa') File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 177, in translate translated = self.translate(item, dest=dest, src=src, **kwargs) File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 182, in translate data = self._translate(text, dest, src, kwargs) File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 78, in _translate token = self.token_acquirer.do(text) File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\gtoken.py", line 194, in do self._update() File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\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' 
C:\Users\Max\Desktop>python --version Python 3.10.8 

Content of init.py file:

"""Free Google Translate API for Python. Translates totally free of charge.""" __all__ = 'Translator', __version__ = '3.0.0' from googletrans.client import Translator from googletrans.constants import LANGCODES, LANGUAGES # noqa 

The text was updated successfully, but these errors were encountered:

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

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

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

Comments

image

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

Читайте также:  opacity

The text was updated successfully, but these errors were encountered:

I am getting this error too. It was starting 28 october.

Win8.1 last updated, Python version 3.6.6, googletrans 3.0.0,

same here.
googletrans 3.0.0, Python 3.8, Linux Ubuntu 20.04.

In a list of 10 words to translate, 2 or 3 would generate the error.
Threading and pausing (1s) improves the problem but does not suppress it.

i test it on ubuntu server and windows 10 but not work

Could you let me know your location and internet service provider? and did you check if it’s working on translate.google.com? Because this library is not an official implementation I need you to check your network condition or elaborate on what’s giving your problem so that I can confirm this issue and help you.

Could you let me know your location and internet service provider? and did you check if it’s working on translate.google.com? Because this library is not an official implementation I need you to check your network condition or elaborate on what’s giving your problem so that I can confirm this issue and help you.

Russia, Rostov on Don, ISP: Megalink. translate.goole.com is working without problems.

I’m also getting same issue.

Note sure if it’s related, but over on gTTS they have similar issues with accessing google translate, but then for text-to-speech. One user reported that switching from urllib.requests to requests fixed the issue:

It might be worthwhile experimenting with vanilla requests instead of httpx.

I’ve tried reproducing this several times but so far I don’t think I can easily reproduce this in my environment (from the major ISPs in South Korea: Korea Telecom, SK Broadband, and U+.)

Python 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from googletrans import Translator >>> t = Translator() >>> t.translate('asdf')

However, I’m investigating this issue further right now and will get back to you shortly — I believe it’s related to something strange happening with Google’s anti-spamming work. If someone else has experienced similar or the same issues please submit to this issue with such details as ISPs, location, and whether it happens consistently at all or not.

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.

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.

Thanks for your information. I will try testing on other networks using proxies.

Читайте также:  Sublime text html css js prettify

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.

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.

Could you guys here test this and let me know if it fixes the issue?

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.

Could you guys here test this and let me know if it fixes the issue?

i also got this error right now.
i am a student from Taiwan. My ISP is TANet. And i try translate.goole.com on Chrome is okay without any problems.
thanks.

i also got this error right now.
i am a student from Taiwan. My ISP is TANet. And i try translate.goole.com on Chrome is okay without any problems.
thanks.

But after i try it on my other computer with Linux Ubuntu 18.04 (never install the «googletrans»), it performed okay. So i think it might be banned by Google, and it’ll be banned for a long time.

I’m actually having the same issue running googletrans inside a docker container. The error would stop all the processes of the container, but as soon as i restart the container, googletrans is not returning any error for the current process.
In my case, i don’t think it can be a ban from Google, otherwise it couldn’t not work when i restart my container

Hi all,
We’ve been using py googletrans for a few weeks by now. Everything was going on ok, but it turned to go into «AttributeError: ‘NoneType’ object has no attribute ‘group'» error since a few days.
I figured out that the token generation in gtoken.py was involved as it is not retrieved ok by requesting google. I tried to implement a retry to recall the _update() function until it provides a valid token. This solution does not work as it keeps stuck in the retry loop (i.e. it never gets a proper token . ).
Sure I would be interested in contributing to the solution, and/or get the issue solving if any.

I’m actually having the same issue running googletrans inside a docker container. The error would stop all the processes of the container, but as soon as i restart the container, googletrans is not returning any error for the current process.
In my case, i don’t think it can be a ban from Google, otherwise it couldn’t not work when i restart my container

I faced this behaviour as after a certain period of time a new request submit works fine .

Читайте также:  Str to float python dataframe

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.

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.

@VOINTENT: Implemented as of, got stability back ! 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.

Thanks, it worked when using only one instance of the class.

Tried the one instance solution worked for a while but now it’s back.

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. 🙂

It worked for me on detecting language. Thanks =]

@ssut
pip install googletrans==4.0.0-rc1 worked perfectly for me. I’m using Python 3.9.1.
mega thx ❤️ 💯

Still getting the JSON object must be str, bytes or bytearray, not NoneType when passing a string greater than 5k and I have uninstalled / reinstalling googletrans==4.0.0rc1

Is this normal?? Has this specific issue been addressed in rc1?

This problem only occurs with googletrans==4.0.0rc1

It works fine on googletrans==3.1.0a0

I have tried googletrans==4.0.0-rc1 and googletrans==3.1.0a0
example: x = trans.translate(«hello»,dest=»am»)
Error:

Traceback (most recent call last): File "", line 1, in File "C:\UsersuserPycharmProjects\AndroidXMLTranslate\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\client.py", line 172, in translate data = self._translate(text, dest, src) File "C:\UsersuserPycharmProjects\AndroidXMLTranslate\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\client.py", line 75, in _translate token = self.token_acquirer.do(text) File "C:\UsersuserPycharmProjects\AndroidXMLTranslate\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\gtoken.py", line 186, in do self._update() File "C:\UsersuserPycharmProjects\AndroidXMLTranslate\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\gtoken.py", line 65, in _update code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '') AttributeError: 'NoneType' object has no attribute 'group' 

Источник

Оцените статью