[英]AttributeError: 'NoneType' object has no attribute 'group' in googletrans
[英]AttributeError: 'NoneType' object has no attribute 'group' while using googletrans library
以前一切正常,但現在當我嘗試使用 googletrans 庫時出錯。 這是我的代碼
import googletrans
from googletrans import Translator
translator = Translator()
df['data'] = df['tweet'].apply(lambda x: translator.translate(x, dest='en').text)
0 | 鳴叫 |
---|---|
0 | Heureusement que Macron n'a pas Profité de la guerre en Ukraine pour être réélu mdr |
1 | L'Ukraine Ce 支付了令人敬畏的 N'est-ce pas Macron le fou |
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-1c7cdbf959e6> in <module>
4
5 translator = Translator()
----> 6 df['data'] = df['tweet'].apply(lambda x: translator.translate(x, dest='en').text)
7
8 df['data'].to_csv('Dataset_EN.csv')
~\anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
4136 else:
4137 values = self.astype(object)._values
-> 4138 mapped = lib.map_infer(values, f, convert=convert_dtype)
4139
4140 if len(mapped) and isinstance(mapped[0], Series):
pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-4-1c7cdbf959e6> in <lambda>(x)
4
5 translator = Translator()
----> 6 df['data'] = df['tweet'].apply(lambda x: translator.translate(x, dest='en').text)
7
8 df['data'].to_csv('Dataset_EN.csv')
~\anaconda3\lib\site-packages\googletrans\client.py in translate(self, text, dest, src, **kwargs)
180
181 origin = text
--> 182 data = self._translate(text, dest, src, kwargs)
183
184 # this code will be updated when the format is changed.
~\anaconda3\lib\site-packages\googletrans\client.py in _translate(self, text, dest, src, override)
76
77 def _translate(self, text, dest, src, override):
---> 78 token = self.token_acquirer.do(text)
79 params = utils.build_params(query=text, src=src, dest=dest,
80 token=token, override=override)
~\anaconda3\lib\site-packages\googletrans\gtoken.py in do(self, text)
192
193 def do(self, text):
--> 194 self._update()
195 tk = self.acquire(text)
196 return tk
~\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 版本或 4.0.0-rc1。
在這里檢查您的 googletrans 版本
pip freeze
在這里安裝 googletrans 版本 4.0.0-rc1
install googletrans==4.0.0-rc1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.