![](/img/trans.png)
[英]AttributeError: 'NoneType' object has no attribute 'group' in googletrans
[英]Python (googletrans) - AttributeError: 'NoneType' object has no attribute 'group'
嘗試使用googletrans檢測 Python 中的語言代碼。 但它會產生錯誤(有關信息,請參閱錯誤塊)。
需要相同的解決方案
代碼:
import googletrans
from googletrans import Translator
translator = Translator()
result = translator.translate('Mitä sinä teet')
print(result.src)
print(result.dest)
print(result.origin)
print(result.text)
print(result.pronunciation)
錯誤:
C:\ProgramData\Anaconda3\lib\site-packages\googletrans\gtoken.py in _update(self)
60
61 # this will be the same as python code after stripping out a reserved word 'var'
---> 62 code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
63 # unescape special ascii characters such like a \x3d(=)
64 code = code.encode().decode('unicode-escape')
AttributeError: 'NoneType' object has no attribute 'group'
這是googletrans
庫的 github 頁面中報告的已知問題。 在那里查看修復的狀態和潛在的解決方法: https://github.com/ssut/py-googletrans/issues 。
根據最近的評論,安裝不同的版本googletrans==4.0.0-rc1
似乎可以工作,但有一些警告:
fire17 於16 天前發表評論
正常 pip 安裝失敗但卸載重裝
googletrans==4.0.0-rc1
然后工作:)
雖然 object 很奇怪,但我可以訪問翻譯后的文本,例如a = translator.translate("hi") translated_text = a.__dict__()["text"]
它在重新安裝 googletrans 后工作
pip 安裝 googletrans==4.0.0-rc1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.