简体   繁体   English

AttributeError:“NoneType”对象在使用 googletrans 库时没有属性“组”

[英]AttributeError: 'NoneType' object has no attribute 'group' while using googletrans library

everything work before but it error now when i try using googletrans library.以前一切正常,但现在当我尝试使用 googletrans 库时出错。 here my code这是我的代码

import googletrans    
from googletrans import Translator

translator = Translator()
df['data'] = df['tweet'].apply(lambda x: translator.translate(x, dest='en').text)
0 0 tweet鸣叫
0 0 Heureusement que Macron n'a pas profité de la guerre en Ukraine pour être réélu mdr Heureusement que Macron n'a pas Profité de la guerre en Ukraine pour être réélu mdr
1 1 L'Ukraine Ce pays formidable N'est-ce pas Macron le fou 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'

your code work properly for me.你的代码对我来说正常工作。 make sure you have the latest googletrans version or 4.0.0-rc1.确保您拥有最新的 googletrans 版本或 4.0.0-rc1。

here for check your googletrans version在这里检查您的 googletrans 版本

pip freeze

and here for install googletrans version 4.0.0-rc1在这里安装 googletrans 版本 4.0.0-rc1

install googletrans==4.0.0-rc1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'NoneType' object 在 googletrans 中没有属性 'group' - AttributeError: 'NoneType' object has no attribute 'group' in googletrans AttributeError: 'NoneType' object 没有属性 'group' googletrans python - AttributeError: 'NoneType' object has no attribute 'group' googletrans python Python (googletrans) - AttributeError: 'NoneType' object 没有属性 'group' - Python (googletrans) - AttributeError: 'NoneType' object has no attribute 'group' AttributeError: 'NoneType' object 在使用谷歌翻译时没有属性'group' - AttributeError: 'NoneType' object has no attribute 'group' while using Google translator Googletrans API 错误 'NoneType' object 没有属性 '组' - Googletrans API Error 'NoneType' object has no attribute 'group' googletrans 停止工作并出现错误“NoneType” object 没有属性“group” - googletrans stopped working with error 'NoneType' object has no attribute 'group' 我不明白为什么 python 中的 googletrans 不工作,它给出错误: AttributeError: 'NoneType' object has no attribute 'group' - I can't understand why googletrans in python isn't working, it gives error: AttributeError: 'NoneType' object has no attribute 'group' AttributeError:使用re.match时&#39;NoneType&#39;对象没有属性&#39;group&#39; - AttributeError: 'NoneType' object has no attribute 'group' while using re.match 使用PDFminer作为库:“AttributeError:&#39;NoneType&#39;对象没有属性&#39;getobj&#39;” - Using PDFminer as a library: “AttributeError: 'NoneType' object has no attribute 'getobj'” AttributeError:&#39;NoneType&#39;对象没有属性&#39;group&#39;错误 - AttributeError: 'NoneType' object has no attribute 'group' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM