簡體   English   中英

AttributeError: 'NoneType' object 沒有屬性 'group' googletrans python

[英]AttributeError: 'NoneType' object has no attribute 'group' googletrans python

Windows 7

Python 3.8.2

谷歌翻譯 3.0.0

from googletrans import Translator

text = 'hello'
translator = Translator()
result = translator.translate(text).src
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\AB\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
googletrans\client.py", line 182, in translate
    data = self._translate(text, dest, src, kwargs)
  File "C:\Users\AB\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
googletrans\client.py", line 78, in _translate
    token = self.token_acquirer.do(text)
  File "C:\Users\AB\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
googletrans\gtoken.py", line 194, in do
    self._update()
  File "C:\Users\AB\AppData\Local\Programs\Python\Python38-32\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'

在一切正常之前,稍后開始出現這些錯誤,現在每次調用 function 后都會出現此錯誤。

試試 google_trans_new。 https://github.com/lushan88a/google_trans_new

pip install google_trans_new
from google_trans_new import google_translator
translator = google_translator()  
translate_text = translator.translate('Hello!',lang_src='en', lang_tgt='de')  
print(translate_text)

-> Hallo!

您必須通過鍵入 pip install googletrans==4.0.0-rc1 將 googletrans 版本從 3.0.0 版增加到 4.0.0 版

你必須使用 googletrans pip 的中央版本安裝 googletrans==4.0.0-rc1 為我工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM