简体   繁体   中英

I am using python3 and I want to translate some text, So I used “googletrans” package, but I am getting some error

My Code:

>> from googletrans import Translator translator = Transltor()
>> translator.translate("Hello",dest="hi") # "hi"  = in hindi language

But I am getting an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\YourTranslator\env\lib\site-packages\googletrans\client.py", line 182, in translate
    data = self._translate(text, dest, src, kwargs)
  File "F:\YourTranslator\env\lib\site-packages\googletrans\client.py", line 78, in _translate
    token = self.token_acquirer.do(text)
  File "F:\YourTranslator\env\lib\site-packages\googletrans\gtoken.py", line 194, in do
    self._update()
  File "F:\YourTranslator\env\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'

using python3, pip 2020 latest version Thanks In Advance

Alright Guys, I found the answer

first you have to uninstall your googletrans

pip install googletrans

And then install this one:

pip install googletrans==3.1.0a0

Error solved Found from here

I dont know if it works for you, but using google_trans_new works for me.

to install:

pip install google_trans_new

to use:

from google_trans_new import google_translator
translator = google_translator()
mystring = "pick your language"
result = translator.translate(mystring, lang_tgt = "de")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM