py-googletrans
py-googletrans copied to clipboard
AttributeError: 'NoneType' object has no attribute 'group'
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
Probably helpful
Got the same problem
Also got the same problem...
I currently have this problem as well
Actually, I just got it to fix by updating to the newest version. That will solve the problem
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?
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
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
the same problem here.
The same problem here too
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.
Try pip install googletrans==4.0.0-rc1
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
However, this link worked for me.
It uses an older version of googletrans
pip install googletrans==3.1.0a0
It works for me
Weird, do you have a sample code @Yildirimm?
However, this link worked for me. It uses an older version of googletrans
pip install googletrans==3.1.0a0
Excellent This Worked for me!
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?
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.
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.
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
Version 4.0.0-rc1 did the trick for me