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

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

Open
Mohammadwh opened this issue Oct 29, 2020 · 195 comments
Assignees

Comments

@Mohammadwh
Copy link

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

@ssut ssut self-assigned this Oct 30, 2020
@ssut
Copy link
Owner

ssut commented Oct 30, 2020

It seems the problem comes from such as network environment, rate limits. Could you provide your environment info, e.g. OS, ISP(your network provider), etc. Also please let me know whether it's okay from translate.google.com.

@1e3m
Copy link

1e3m commented Oct 30, 2020

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

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

@laubil
Copy link

laubil commented Oct 30, 2020

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.

@Mohammadwh
Copy link
Author

Mohammadwh commented Oct 30, 2020

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

@ssut
Copy link
Owner

ssut commented Oct 30, 2020

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.

@1e3m
Copy link

1e3m commented Oct 30, 2020

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.

@sahil-gorivale
Copy link

I'm also getting same issue.

@pbienst
Copy link

pbienst commented Nov 1, 2020

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:

pndurette/gTTS#226

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

@ssut
Copy link
Owner

ssut commented Nov 2, 2020

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')
<googletrans.models.Translated object at 0x104596790>

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.

@ssut ssut changed the title error in result error in result (AttributeError: 'NoneType' object has no attribute 'group') Nov 2, 2020
@ssut ssut pinned this issue Nov 2, 2020
@suciokhan
Copy link

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.

@ssut
Copy link
Owner

ssut commented Nov 2, 2020

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.

@pbienst
Copy link

pbienst commented Nov 2, 2020

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.

@ssut
Copy link
Owner

ssut commented Nov 2, 2020

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?

@Mohammadwh
Copy link
Author

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 test it
not work 😐

@zz860808
Copy link

zz860808 commented Nov 3, 2020

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.

@zz860808
Copy link

zz860808 commented Nov 3, 2020

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.

@Dauflo
Copy link

Dauflo commented Nov 3, 2020

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

@alainrouillon
Copy link
Contributor

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.

@alainrouillon
Copy link
Contributor

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

@VOINTENT
Copy link

VOINTENT commented Nov 3, 2020

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.

@alainrouillon
Copy link
Contributor

alainrouillon commented Nov 3, 2020

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

@khannoaman
Copy link

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.

@vonblanc
Copy link

vonblanc commented Nov 4, 2020

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

@Sn1F3rt
Copy link

Sn1F3rt commented Nov 4, 2020

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. :)

@Poycodon9x
Copy link

pip install google_trans_new
I have removed googletrans and replaced the state Cai now. It's working again

@SuperZombi
Copy link

pip install googletrans==4.0.0rc1
This is pre-release. It's working for me.
Author, publish this pre-release as main.

@igormcsouza
Copy link

igormcsouza commented Jun 2, 2021

Using Python 3.7 and googletrans==4.0.0rc1 worked like a charm for me! :D

@danpaldev
Copy link

This is still an issue. Use pip install googletrans==4.0.0rc1 and you will have no problems.

@ghost
Copy link

ghost commented Jun 9, 2021

the issue is still present for bulk translations

@liliana3186
Copy link

I have the same issue Using python 3.7.6 and googletrans==4.0.0rc1

@aprknight
Copy link

googletrans 3.0.0 which, at the time of writing, is the released version with Python 3.9.6, macOS 11.5, ISP is BT in the United Kingdom and the 'NoneType object has no attribute group...' issue is a problem for me.

It is obvious from the error trace that the problem lies in: RE_TKK.search(r.text) which is returning None.

Under what circumstances would it do that?

@ValleSell
Copy link

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.

Could you explain how to do that with an example please?

@memory4963
Copy link

I met this issue also, and I fixed it by removing the param "service_urls" when constructing the "Translator()"

from

translator = Translator(service_urls=[
       'translate.google.com',
       'translate.google.com.hk',
       'translate.google.co.kr',
     ])

to

translator = Translator()

hope this helps :)

@Avazart
Copy link

Avazart commented May 26, 2022

File "C:\Users\xxx\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'

Author used regex for parse html :(

@DarkRedman
Copy link

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.

Doesn't work for me even using only one instance.

@MiKatre
Copy link

MiKatre commented Jun 20, 2022

What worked for me today was

pip uninstall googletrans==4.0.0-rc1

pip install googletrans==3.1.0a0

(solution from https://stackoverflow.com/a/69271089/7292383)

@DSPerson
Copy link

  1. pip install googletrans==3.1.0a0
  2. translator = Translator()
  3. don't use Translator() service_urls parameter, it work

@lgbongiolo
Copy link

@alessandrokr
Copy link

I fixed it with with changing the the service_urls with the non web version:
service_urls = ["translate.googleapis.com"]

@frannylac
Copy link

translate.googleapis.com

this url was removed... returns 404

@DoubleStarK
Copy link

Python 3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
using googletrans==4.0.0rc1, works fine.

@vasamaximov
Copy link

googletrans==4.0.0rc1, pythonwin 3.11.4 - works perfectly too

c-goosen pushed a commit to c-goosen/py-googletrans that referenced this issue Sep 19, 2024
* fix: issue ssut#234 - extend service url to direct api

fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token

* fix: issue ssut#234 - extend use of direct api

fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token

* fix: issue ssut#234 - extend use of direct api

fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token

* fix: issue ssut#234 - extend use of direct api

fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token

* fix: issue ssut#234 - extend use of direct api

fix: issue ssut#234 - manage use of translate.googleapis.com which does not need token
c-goosen pushed a commit to c-goosen/py-googletrans that referenced this issue Sep 19, 2024
c-goosen pushed a commit to c-goosen/py-googletrans that referenced this issue Sep 19, 2024
c-goosen pushed a commit to c-goosen/py-googletrans that referenced this issue Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.