py-googletrans icon indicating copy to clipboard operation
py-googletrans copied to clipboard

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

Open BaseMax opened this issue 2 years ago • 22 comments

Source code:

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)

Output:

C:\Users\Max\Desktop>python translate.py
Traceback (most recent call last):
  File "C:\Users\Max\Desktop\translate.py", line 10, in <module>
    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'

More information:

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

BaseMax avatar Feb 08 '23 10:02 BaseMax

Probably helpful

l0rtk avatar Feb 10 '23 10:02 l0rtk

Got the same problem

Charles-ux-bit avatar Feb 18 '23 06:02 Charles-ux-bit

Also got the same problem...

excelant100 avatar Feb 18 '23 23:02 excelant100

I currently have this problem as well

Kasherpete avatar Feb 19 '23 02:02 Kasherpete

Actually, I just got it to fix by updating to the newest version. That will solve the problem

Kasherpete avatar Feb 19 '23 02:02 Kasherpete

Actually, I just got it to fix by updating to the newest version. That will solve the problem

Oh nice, How and to which version?

BaseMax avatar Feb 19 '23 04:02 BaseMax

Actually, I just got it to fix by updating to the newest version. That will solve the problem

Oh nice, How and to which version?

4.0.0-rc1 this version works

l0rtk avatar Feb 19 '23 10:02 l0rtk

Actually, I just got it to fix by updating to the newest version. That will solve the problem

Oh nice, How and to which version?

pip install googletrans==4.0.0-rc1

decibel1030 avatar Mar 22 '23 11:03 decibel1030

the same problem here.

bigplayer-ai avatar Apr 10 '23 19:04 bigplayer-ai

The same problem here too

alphaoumardev avatar Apr 24 '23 05:04 alphaoumardev

I remember that I was able to fix this issue, but I cannot remember exactly how. However It seems that it works on version 4.0.0-rc1, so instead of doing pip install try to force it to do the most recent version. Seems backwards but I believe that is how I fixed it, all I remember was that it was an easier fix than I thought.

Kasherpete avatar Apr 25 '23 01:04 Kasherpete

Try pip install googletrans==4.0.0-rc1

Kasherpete avatar Apr 25 '23 01:04 Kasherpete

Try pip install googletrans==4.0.0-rc1

I installed it but now it gives the following error.

File "C:\Users\...\Programs\Python\Python310\lib\json\__init__.py", line 339, 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

Yildirimm avatar May 19 '23 10:05 Yildirimm

However, this link worked for me. It uses an older version of googletrans pip install googletrans==3.1.0a0

Yildirimm avatar May 19 '23 10:05 Yildirimm

It works for me

alphaoumardev avatar May 19 '23 11:05 alphaoumardev

Weird, do you have a sample code @Yildirimm?

Kasherpete avatar May 19 '23 21:05 Kasherpete

However, this link worked for me. It uses an older version of googletrans pip install googletrans==3.1.0a0

Excellent This Worked for me!

xdevfaheem avatar May 27 '23 13:05 xdevfaheem

there is a way to install last version with conda? I mean, which will be the solution to avoid conflicts for an env fully created with conda?

cgaravitoc avatar Jun 13 '23 22:06 cgaravitoc

For those who have the same problem. Just make sure; don't forget to install the working versions (4.0.0-rc1 or 3.1.0a0) in the venv, like me. it took me 1 hour to figure out where I went wrong.

ErtungaYusuf avatar Jun 29 '23 21:06 ErtungaYusuf

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 16 '23 22:09 stale[bot]

i am having the same issue. i have tried both version 4.0.0-rc1 and 3.1.0a0. both of them gives error none type has no attribute group. the code was working find in my local host. but in client server it does not work. what is the issue. i am using 3.1.0a0 as of now

MadhavPancholi avatar Oct 13 '23 12:10 MadhavPancholi

Version 4.0.0-rc1 did the trick for me

sarc0m3 avatar Oct 31 '23 21:10 sarc0m3