![](/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.