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

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

Open
BaseMax opened this issue Feb 8, 2023 · 22 comments
Open

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

BaseMax opened this issue Feb 8, 2023 · 22 comments

Comments

@BaseMax
Copy link

BaseMax commented Feb 8, 2023

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
@l0rtk
Copy link

l0rtk commented Feb 10, 2023

Probably helpful

@Charles-ux-bit
Copy link

Got the same problem

@excelant100
Copy link

Also got the same problem...

@Kasherpete
Copy link

I currently have this problem as well

@Kasherpete
Copy link

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

@BaseMax
Copy link
Author

BaseMax commented Feb 19, 2023

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?

@l0rtk
Copy link

l0rtk commented Feb 19, 2023

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

@decibel1030
Copy link

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

@bigplayer-ai
Copy link

the same problem here.

@alphaoumardev
Copy link

The same problem here too

@Kasherpete
Copy link

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
Copy link

Try pip install googletrans==4.0.0-rc1

@Yildirimm
Copy link

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
Copy link

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

@alphaoumardev
Copy link

It works for me

@Kasherpete
Copy link

Weird, do you have a sample code @Yildirimm?

@xdevfaheem
Copy link

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

Excellent This Worked for me!

@cgaravitoc
Copy link

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?

@ErtungaYusuf
Copy link

ErtungaYusuf commented Jun 29, 2023

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.

@stale
Copy link

stale bot commented Sep 16, 2023

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 stale bot added the wontfix label Sep 16, 2023
@MadhavPancholi
Copy link

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

@sarc0m3
Copy link

sarc0m3 commented Oct 31, 2023

Version 4.0.0-rc1 did the trick for me

@stale stale bot removed the wontfix label Oct 31, 2023
holybiber added a commit to 4training/pywikitools that referenced this issue Dec 17, 2023
With googletrans-3.0.0 I had the following error:
AttributeError: 'NoneType' object has no attribute 'group'
See ssut/py-googletrans#366 - requiring
4.0.0rc1 fixed it.
@bymaer bymaer mentioned this issue Jan 17, 2024
6 tasks
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

No branches or pull requests