problems with googletrans module

286 Views Asked by At

im trying to make a small graphic translator in python using googletrans. It runs fine until I press the translate button this is the error message I get

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\python\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:\Users\lenue\OneDrive\Desktop\run.py", line 36, in run
translation = translator.translate('How are you', src= 'en', dest = 'fr')
File "C:\python\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\python\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\python\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\python\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'

I was using a different module but there were import problems so I installed googletrans this is all my code

import os
from googletrans import Translator
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk

class Window(object):
def __init__(self, master):
    frame = Frame(master)
    frame.grid()
    self.options = ['French' , 'English' , 'Spansih']
    self.text_label = Label(root, text="Enter text : ")
    self.text_label.grid(column = 0, row = 0)
    self.imput = Entry(root)
    self.imput.grid(column = 1, row = 0)
    self.selection_frame = LabelFrame(root, text = "Languages")
    self.selection_frame.grid(column = 0, row = 1, columnspan = 2)
    self.langs = ttk.Combobox(self.selection_frame, values = self.options)
    self.langs.grid(column = 0, row = 1)
    self.result = Label(root, text = "")
    self.result.grid(column = 0, row = 2, columnspan = 2)
    self.button = Button(root, text = "Translate", command = self.run)
    self.button.grid(column = 0, row = 3, columnspan = 2)

def run(self):

    translator = Translator()
    text = self.imput.get()
    lang = self.langs.get()
    if lang == 'French':
        lc = 'fr'
    if lang == 'English':
        lc = 'en'
    if lang == 'Spanish':
         lc = 'es'
    translation = translator.translate(text, dest = lc)
    self.result.configure(text = translation)
root = Tk()
root.title = ("run")
Window(root)
root.mainloop()
2

There are 2 best solutions below

0
On

you should upgrade to the version 3.1.0a0 they have done a temporarily fix to this issue

just run pip install googletrans==3.1.0a0

3
On

Just install the alpha version of the googletrans with pip install googletrans==3.1.0a0.

The other versions doesnt seem to work because of some bug. The same issue has been discussed on github here.

As about the documentation its same as googletrans