ssut/py-googletrans

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

MGriot opened this issue · 15 comments

  • bug report
  • feature request

When I try to follow the guide given in the documentation I get an error.

from googletrans import Translator
translator = Translator()

translator.translate('Mitä sinä teet')


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

Have the same issue.

Solved after installing googletrans==4.0.0rc1

Have the same issue with googletrans==4.0.0rc1.

Can the maintainers update the release version?

I have the same issue and would appreciate update

I have the same issue and would appreciate update

Same issue for me and I'm not able to use the library: it seems doesn't work. Any update?

blu@xxx:~/bots/discord/blacksquad $ python3 __init__.py                     
2022-10-21 19:58:36,519 INFO sqlalchemy.engine.Engine [raw sql] ()              
2022-10-21 19:58:36,523 INFO sqlalchemy.engine.Engine SELECT @@sql_mode         
2022-10-21 19:58:36,526 INFO sqlalchemy.engine.Engine SELECT @@lower_case_table_
names                                                                           
2022-10-21 19:58:36,532 INFO sqlalchemy.engine.Engine BEGIN (implicit)          
2022-10-21 19:58:36,542 INFO sqlalchemy.engine.Engine SELECT news.timestamp AS n
de AS news_title_de, news.content AS news_content, news.content_de AS news_conte
nt_de, news.author AS news_author, news.url AS news_url, news.severity AS news_s
FROM news                                                                       
2022-10-21 19:58:36,542 INFO sqlalchemy.engine.Engine [generated in 0.00063s] ()
Traceback (most recent call last):                                              
  File "/home/blu/bots/discord/blacksquad/__init__.py", line 22, in <module>    
    translate_all_sql()                                                         
  File "/home/blu/bots/discord/blacksquad/db/sql.py", line 26, in translate_all_
sql                                                                             
    item.title_de = translate(item.title)                                       
  File "/home/blu/bots/discord/blacksquad/translate/google.py", line 6, in trans
late_google                                                                     
    return translator.translate(text, src=src, dst=dst).text                    
  File "/home/blu/.local/lib/python3.9/site-packages/googletrans/client.py", lin
e 182, in translate                                                             
    data = self._translate(text, dest, src, kwargs)                             
  File "/home/blu/.local/lib/python3.9/site-packages/googletrans/client.py", lin
e 78, in _translate                                                             
    token = self.token_acquirer.do(text)                                        
  File "/home/blu/.local/lib/python3.9/site-packages/googletrans/gtoken.py", lin
e 194, in do                                                                    
    self._update()                                                              
  File "/home/blu/.local/lib/python3.9/site-packages/googletrans/gtoken.py", lin
e 62, in _update                                                                
    code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

FYI, this seems to be caused by the "Before you continue to Google" page that requires accepting cookie policy before using the service (you can check this by using private mode and opening translate.google.com page). After clicking accept, one can access the service as usual.
Idea: It might be possible to use "http_request" package that allows executing Javascript that can programmatically click the accept button, e.g., something like:

var list = document.getElementsByTagName("button")
for (i = 0; i < list.length; ++i) {
	if (list[i].getInnerHTML().search('Accept all')>-1) {
		list[i].click();
		break;
	};
}

Unfortunately I couldn't get this to work yet. Didn't quite understand how this "r.html.render" function is supposed to work in http_request...

This should be a high priority and fixed ASAP! Sadly it doesn't really get maintained anymore. I will look into the code after the holidays and try to find a fix.

This is not really a "fix" for the problem, but fwiw I switched to using the official Google Cloud Translation API, and it turns out the first 500k characters a month is free. Since this breaks the TOS anyway, might be worth to just switch over. It's just a little bit of a hassle to setup authentication.

stale commented

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.

Not resolved yet...

Not resolved yet...

The only way is to use older version of the library.

stale commented

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.