Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team

I need help with this issue, basically i am building a google translation using pandas but strange part when i compile it below are the output from my IDE;

// exception from the IDE
<pre>Traceback (most recent call last):
  File "C:\Users\Zux\PycharmProjects\ClassCentral\", line 35, in <module>
    df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translator.translate(x, dest='hi').text)
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\pandas\core\", line 4771, in apply
    return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\pandas\core\", line 1123, in apply
    return self.apply_standard()
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\pandas\core\", line 1174, in apply_standard
    mapped = lib.map_infer(
  File "pandas\_libs\lib.pyx", line 2924, in pandas._libs.lib.map_infer
  File "C:\Users\Zux\PycharmProjects\ClassCentral\", line 35, in <lambda>
    df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translator.translate(x, dest='hi').text)
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\googletrans\", line 182, in translate
    data = self._translate(text, dest, src, kwargs)
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\googletrans\", line 78, in _translate
    token =
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\googletrans\", line 194, in do
  File "C:\Users\Zux\PycharmProjects\ClassCentral\ClassCentral\Lib\site-packages\googletrans\", line 62, in _update
    code ='var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

Process finished with exit code 1

What I have tried:

from googletrans import Translator
from selenium import webdriver
from import By
from import WebDriverWait
from import expected_conditions
import pandas as pd
import urllib.request as urllib2
import time

chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=chrome_options)
url = ""

translator = Translator()

    while True:
        # wait until button is clickable
        WebDriverWait(driver, 1).until(
            expected_conditions.element_to_be_clickable((By.XPATH, "//button[@data-name='LOAD_MORE']"))
except Exception as e:

all_courses = driver.find_element(by=By.CLASS_NAME, value='catalog-grid__results')
courses = all_courses.find_elements(by=By.CSS_SELECTOR, value='[class="color-charcoal course-name"]')

df = pd.DataFrame([[course.text, course.get_attribute('href')] for course in courses],
                  columns=['Title (eng)', 'Link'])

df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translator.translate(x, dest='hi').text)

Updated 6-Mar-23 19:22pm
Richard MacCutchan 5-Mar-23 7:33am    
The expression does not return a valid reference. So something is missing from your dataframe at the line:
df['Title (hin)'] = df['Title (eng)'].apply(lambda x: translator.translate(x, dest='hi').text)
Gcobani Mkontwana 5-Mar-23 9:27am    
@Richard MacCuthan, i went and check under the site-package where the issue is. on this file under googletrans packge( The method accepts this as string ;
def _translate(self, text, dest, src, override):
token =
params = utils.build_params(query=text, src=src, dest=dest,
token=token, override=override)

url = urls.TRANSLATE.format(host=self._pick_service_url())
r = self.client.get(url, params=params)

if r.status_code == 200:
data = utils.format_json(r.text)
return data
if self.raise_exception:
raise Exception('Unexpected status code "{}" from {}'.format(r.status_code, self.service_urls))
DUMMY_DATA[0][0][0] = text

1 solution

Hi Team

After doing some research i thought i should post my solution here from this topic. Well i did the following pip installation to work this through on my script.

pip uninstall googletrans

pip install googletrans==3.1.0a0

3. Test and run the code, code executed well with what i expected no errors from the terminal.

In summary there issue was on googletrans somehow, python has the newest library for using googletrans to translate languages check it out. Follow this link here googletrans · PyPI[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900