最近刚开始学习nlp,到了文本增强的互译部分,记录一下调用googletrans遇到的问题
问题1:
ConnectTimeout: timed out
解决方法:
在实例化翻译对象时加入service URL
translator = Translator(service_urls=[
'translate.google.cn',
])
问题2:
googletransAttributeError: ‘NoneType’ object has no attribute ‘group’
解决方法:
卸掉默认版本,安装新版本
pip uninstall googletrans
pip install googletrans==4.0.0rc1
问题3:
在传入list时出现
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
解决方法:
将list转换成json
text = json.dumps([str1,str2],ensure_ascii=False) # 这里传入的是中文,需要注意编码问题