[英]Python (googletrans) - AttributeError: 'NoneType' object has no attribute 'group'
Trying to detect language code in Python using googletrans .尝试使用googletrans检测 Python 中的语言代码。 But it generating ERROR (Refer error block for info).
但它会产生错误(有关信息,请参阅错误块)。
Require solution for the same需要相同的解决方案
Code:代码:
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)
Error:错误:
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'
This is a known, reported issue in the googletrans
library's github page.这是
googletrans
库的 github 页面中报告的已知问题。 Take a look there to see the status of the fix and potential work arounds: https://github.com/ssut/py-googletrans/issues .在那里查看修复的状态和潜在的解决方法: https://github.com/ssut/py-googletrans/issues 。
According to the most recent comment, installing a different version, googletrans==4.0.0-rc1
, appears to work, but with caveats:根据最近的评论,安装不同的版本
googletrans==4.0.0-rc1
似乎可以工作,但有一些警告:
fire17 commented 16 days ago
fire17 于16 天前发表评论
normal pip installation failed but uninstalled and reinstalled正常 pip 安装失败但卸载重装
googletrans==4.0.0-rc1googletrans==4.0.0-rc1
then worked:)然后工作:)
tho the object is wierd, i can access the translated text like虽然 object 很奇怪,但我可以访问翻译后的文本,例如
a = translator.translate("hi") translated_text = a.__dict__()["text"]
It worked post re-installing googletrans它在重新安装 googletrans 后工作
pip install googletrans==4.0.0-rc1 pip 安装 googletrans==4.0.0-rc1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.