python – GoogleTrans API错误 – 期望值:第1行第1列(字符0)
发布时间:2020-12-20 12:14:05  所属栏目:Python  来源:网络整理 
            导读:我在迭代中翻译数千个文本数据时遇到此错误: Expecting value: line 1 column 1 (char 0) 我翻译大量文本的代码: translatedList = []for index,row in df.iterrows(): newrow = copy.deepcopy(row) try: # translate the 'text' column translated = tran
                
                
                
            | 
 我在迭代中翻译数千个文本数据时遇到此错误: 
  
  
  Expecting value: line 1 column 1 (char 0) 我翻译大量文本的代码: translatedList = []
for index,row in df.iterrows():
    newrow = copy.deepcopy(row)
    try:
        # translate the 'text' column
        translated = translator.translate(row['text'],dest='en')
        newrow['translated'] = translated.text
    except Exception as e:
        print(str(e))
        continue
    translatedList.append(newrow)翻译大约2-3k行后,我收到此错误. 解决方法
 我有点想出了问题.我认为这是关于Google API的请求限制. 
  
  我通过在每次迭代时重新初始化翻译器API来解决这个问题: import copy
from googletrans import Translator
translatedList = []
for index,row in df.iterrows():
    # REINITIALIZE THE API
    translator = Translator()
    newrow = copy.deepcopy(row)
    try:
        # translate the 'text' column
        translated = translator.translate(row['text'],dest='en')
        newrow['translated'] = translated.text
    except Exception as e:
        print(str(e))
        continue
    translatedList.append(newrow)(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
相关内容
- python – 将两个pandas数据帧的值相互组合并完成
- 【Python selenium】
- django中间件 csrf跨站请求伪造 auth模块 settings功能插拔
- 如何在两个元组列表中的值
- 如何利用Python和深度神经网络锁定即将流失的客户?业绩过十
- Java. How to use headless browsers for crawling web and
- 看资深程序员是如何用Python 快速实现 HTTP 和 FTP 服务器的
- 抖音是目前最火的APP!它为何会这么火?Python十行代码爬抖
- 使用Python操作MySQL的一些基本方法
- Python实现批量读取图片并存入mongodb数据库的方法示例
