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' #48

Closed
halleyshx opened this issue Nov 21, 2017 · 42 comments
Closed

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

halleyshx opened this issue Nov 21, 2017 · 42 comments

Comments

@halleyshx
Copy link

halleyshx commented Nov 21, 2017

My script like this:
#-- coding:utf-8 --
from googletrans import Translator
import sys
import io

translator = Translator()
tanstext = u'我们'
tran_ch = translator.translate(tanstext ).text
print tran_ch
###############
yesterday this is ok and no problem,but today I run my script without internet, show some problem.And I run the script in the internet environment, but it's show same problem,can't run.
The cmd show the Traceback like this:
Traceback (most recent call last):
File "D:\JDstory\workstory\translation-project\filetocut\trans-test.py", line
10, in
tran_ch = translator.translate(tanstext).text
File "D:\software\Python27\lib\site-packages\googletrans\client.py", line 132,
in translate
data = self._translate(text, dest, src)
File "D:\software\Python27\lib\site-packages\googletrans\client.py", line 57,
in _translate
token = self.token_acquirer.do(text)
File "D:\software\Python27\lib\site-packages\googletrans\gtoken.py", line 180,
in do
self._update()
File "D:\software\Python27\lib\site-packages\googletrans\gtoken.py", line 59,
in _update
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
#########################
That's why? Thank you so much!

@Andy671
Copy link

Andy671 commented May 27, 2018

Have you found a solution?

@Larkina
Copy link

Larkina commented Sep 19, 2018

This means google banned your IP.

@Darkblader24
Copy link

Wrong, this happens when Google directly sends you the raw token. They do this for a short time after maintenance, not sure why.

@MTL1991
Copy link

MTL1991 commented Sep 20, 2018

Hi,

from yesterday I have this "error". How do you think that I could fix it. I just created other server to execute my code and the result it's the same :(

Thanks

@Darkblader24
Copy link

See here for the fix: #78

@MTL1991
Copy link

MTL1991 commented Sep 20, 2018

Perfect! Thanks so much @Darkblader24! This work now for me!

@ariefsibuea
Copy link

ariefsibuea commented Sep 21, 2018

how to use it for translation code above?

@r-bond
Copy link

r-bond commented Sep 21, 2018

go to browser with Google Translate page, try to translate Hello World =)
if you see Error translated - your IP are banned

@ariefsibuea
Copy link

I have tried to translate from Google Translate page and it works. But when I try code above it failed with same error as shown above.

@ariefsibuea
Copy link

See here for the fix: #78

Can I use the code with the translation code by @halleyshx ?

@hrishikeshpatel
Copy link

hrishikeshpatel commented Sep 21, 2018

After applying #78 I got below error. Please help

380             obj, end = self.scan_once(s, idx)
381             except StopIteration:
382             raise ValueError("No JSON object could be decoded")
383         return obj, end

ValueError: No JSON object could be decoded

@joaonetto
Copy link

Looking other places, probably the issue is around a Regex from Google Translate than they use to working on.

Take a look in: pndurette/gTTS#138

@Maldus512
Copy link

See here for the fix: #78

Apologies, I just installed this library via pip and encountered this error. How should I proceed to apply said fix?

@luapp
Copy link

luapp commented Sep 23, 2018

hello, I try today to use the gtts on python but is not working
can somebody help me please ?

the error is:

Exception has occurred: OSError
[Errno 22] Invalid argument: 'C:\test.mp3'
File "C:\Users\Administrator\Desktop\Speech-Recognition.py", line 39, in
speech.save("C:\test.mp3")

My code:

import speech_recognition as sr
from gtts import gTTS
import os
import playsound

while True:

command = 0
speech = 0

mic = sr.Microphone()
r = sr.Recognizer()
with mic as source:
print("Calibrate Microphone")
print("Please wait...")
r.adjust_for_ambient_noise(source, duration=1)
print("listening...")
audio = r.listen(source)

try:
command = (r.recognize_google(audio))
print("you said:"+command)

except sr.UnknownValueError:
print("")

except sr.RequestError:
print("")

if "hello" in command:
print("hello")
speech = gTTS("hello", lang="en")
if os.path.exists("C:\test.mp3"):
print("file exist")
playsound.playsound("C:\test.mp3", True)
else:
print("saving new mp3 sound")
speech.save("C:\test.mp3")
playsound.playsound("C:\test.mp3", True)

@joaonetto
Copy link

@Creator-360 , your code is under gTTS project, please take a look in:

pndurette/gTTS#138

@feifanhanmc
Copy link

same to me TAT

@algoscale1
Copy link

@Darkblader24 My IP is also getting blocked after using the pull request [(https://github.com//pull/78)], although it resolved the "None Type" issue. It happens after 250 requests or something, I have even tried on a different server, the IP is continuously getting blocked after few requests. Earlier I could make thousands of requests and my IP never got blocked. The new pull request has messed up something, any idea?

@ramya-ramanathan
Copy link

ramya-ramanathan commented Oct 22, 2018

Quick question: What is the error you get when your IP is blocked?

Is it ValueError: No JSON object could be decoded ?

@astariul
Copy link

The error when the IP is blocked is Expecting value: line 1 column 1 (char 0)

Any idea how to unblock my IP address ?

@1010Manoj
Copy link

@ramya-ramanathan I am getting ValueError: No JSON object could be decoded
what is this for???

@SmartDev-0205
Copy link

Hello
I get 'NoneType' object has no attribute 'group'
I have tried this
$ pip uninstall googletrans
$ git clone https://github.com/BoseCorp/py-googletrans.git
$ cd ./py-googletrans
$ python setup.py install
But get same issue
Please help me

@bastienboutonnet
Copy link

I've been getting this as well on a recent install of googletrans in a fresh venv:

  File "<truncated_for_privacy>/lib/python3.6/site-packages/googletrans/client.py", line 182, in translate
    data = self._translate(text, dest, src, kwargs)
  File "<truncated_for_privacy>/lib/python3.6/site-packages/googletrans/client.py", line 78, in _translate
    token = self.token_acquirer.do(text)
  File "<truncated_for_privacy>/lib/python3.6/site-packages/googletrans/gtoken.py", line 194, in do
    self._update()
  File "<truncated_for_privacy>/lib/python3.6/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'

@yoyoidea
Copy link

yoyoidea commented Nov 5, 2020

Hello
I get 'NoneType' object has no attribute 'group'
I have tried this
$ pip uninstall googletrans
$ git clone https://github.com/BoseCorp/py-googletrans.git
$ cd ./py-googletrans
$ python setup.py install
But get same issue
Please help me

me, too.

@Hamilkar247
Copy link

still problem exist :'(

ksmin23 added a commit to ksmin23/aws-rss-feed-trans-bot that referenced this issue Nov 8, 2020
- AttributeError: 'NoneType' object has no attribute 'group'
- ssut/py-googletrans#48
ksmin23 added a commit to ksmin23/aws-blog-trans-bot that referenced this issue Nov 8, 2020
- AttributeError: 'NoneType' object has no attribute 'group'
- ssut/py-googletrans#48
@waelmas
Copy link

waelmas commented Nov 15, 2020

Still having this issue too frequently. Impacting our production.

For days we thought we've been doing something wrong...

@ashishalakhani
Copy link

I am seeing this issue as well. I see it on dev and staging environment but not in production.

@markklick206
Copy link

Getting the same "Attribute Error" after GoogleTrans had been working great for months...

  File "C:\Anaconda3\lib\site-packages\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'

@mateoToquica
Copy link

mateoToquica commented Nov 20, 2020

I've been using this library to do research work, where I have to translate several images, at first I thought it was an error in the images because they have different edges and colors, but then I used a time delay for some images that did not work and suddenly they started translating. The problem is that it does not work for all the images, below I show how I use the delay

def translateImg(src):
    img = cv2.imread(src)
    text = pytesseract.image_to_string(img, lang='ara')
    print(text)
    time.sleep(10) # sleep the aplication 10 seconds
    translator = Translator()
    result = translator.translate(text)
    print(result.text)
for x in range(1,28):
    translateImg('../resources/photos/annunciAmaq1/img ('+str(x)+').jpg')

@jmagdeska
Copy link

I'm also getting the same issue, any fix for this?

File "/home/anaconda3/lib/python3.7/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'

I'm using Python 3.7.3 on Ubuntu 20.04 machine

@MartinVinter
Copy link

Hey there,

In another 2 years old thread talking about this issue (which sadly, I cannot find again) it was mentioned that upgrading GoogleTrans helps. It has helped for me too, but only for a short while. In other old threads I have found, it was mentioned, that an older version of the issue was related to a problem with an API key, token or similar. So my theory is that I get another key if I update. Even when there isn't a new version, Anaconda will re-download and install the package. At least you can give it a shot. It is quite easy - run this in Anaconda:

pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade

@sergiomora03
Copy link

Hi, I get the same error.

Python version 3.8.3

@sergiomora03
Copy link

Hey there,

In another 2 years old thread talking about this issue (which sadly, I cannot find again) it was mentioned that upgrading GoogleTrans helps. It has helped for me too, but only for a short while. In other old threads I have found, it was mentioned, that an older version of the issue was related to a problem with an API key, token or similar. So my theory is that I get another key if I update. Even when there isn't a new version, Anaconda will re-download and install the package. At least you can give it a shot. It is quite easy - run this in Anaconda:

pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade

It´s not work. Still the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-f71bcb40be3a> in <module>
----> 1 translator.translate('Hola Mundo')

~\Anaconda3\lib\site-packages\googletrans\client.py in translate(self, text, dest, src)
    170 
    171         origin = text
--> 172         data = self._translate(text, dest, src)
    173 
    174         # this code will be updated when the format is changed.

~\Anaconda3\lib\site-packages\googletrans\client.py in _translate(self, text, dest, src)
     73             text = text.decode('utf-8')
     74 
---> 75         token = self.token_acquirer.do(text)
     76         params = utils.build_params(query=text, src=src, dest=dest,
     77                                     token=token)

~\Anaconda3\lib\site-packages\googletrans\gtoken.py in do(self, text)
    184 
    185     def do(self, text):
--> 186         self._update()
    187         tk = self.acquire(text)
    188         return tk

~\Anaconda3\lib\site-packages\googletrans\gtoken.py in _update(self)
     63 
     64         # this will be the same as python code after stripping out a reserved word 'var'
---> 65         code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
     66         # unescape special ascii characters such like a \x3d(=)
     67         if PY3:  # pragma: no cover

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

@BoyuChen118
Copy link

You can simply overcome this issue by using error handling like so:

while True:
    try:
       # you translation code here
    except:
        print(Exception)
        continue
    break

@ashishalakhani
Copy link

You can simply overcome this issue by using error handling like so:

while True:
    try:
       # you translation code here
    except:
        print(Exception)
        continue
    break

Won't this go in infinite loop?

@NicoCaldo
Copy link

You can simply overcome this issue by using error handling like so:

while True:
    try:
       # you translation code here
    except:
        print(Exception)
        continue
    break

Won't this go in infinite loop?

For some reason, at a certain point, the translation succeed, at least, from my experience

@jmagdeska
Copy link

You can simply overcome this issue by using error handling like so:

while True:
    try:
       # you translation code here
    except:
        print(Exception)
        continue
    break

Won't this go in infinite loop?

Yes, issue is not solved, the program goes to infinite loop.

@ashishalakhani
Copy link

I don't think we can rely on this library for production use. Any other free alternative?

@NicoCaldo
Copy link

I don't think we can rely on this library for production use. Any other free alternative?

It works like a charm for me https://github.com/lushan88a/google_trans_new

@jmagdeska
Copy link

I don't think we can rely on this library for production use. Any other free alternative?

It works like a charm for me https://github.com/lushan88a/google_trans_new

Thank you for sharing this resource, I confirm it works without problems so far.

@MuzzyGH
Copy link

MuzzyGH commented Mar 4, 2021

I don't think we can rely on this library for production use. Any other free alternative?

It works like a charm for me https://github.com/lushan88a/google_trans_new

Be careful this is not Google Translate the output is much lower quality to what you get at https://translate.google.com/

There is a working solution for AHK (https://www.autohotkey.com/boards/viewtopic.php?t=63835). Why can't we make it work in Python?

@subhrasmitdas123
Copy link

subhrasmitdas123 commented Feb 4, 2023

Hello
I tried to make language translator app using the latest version and it worked but whenever i tried to run it any other system it is showing a none type error and to resolve it i unistall the version and tried to run it 3.1.0a0 version and same it is working on my side but the error is the same while running it in other system . what is the solution to it ?

@apollo1234567890
Copy link

Hi !! the same problem.
line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

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