GoogleTrans API错误-预期值:第1行第1列(字符0) [英] GoogleTrans API Error - Expecting value: line 1 column 1 (char 0)
本文介绍了GoogleTrans API错误-预期值:第1行第1列(字符0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在迭代中翻译成千上万个文本数据时出现此错误:
I am having this error when translating thousands of text data in an iteration:
Expecting value: line 1 column 1 (char 0)
我用于翻译大量文本的代码:
My code for translating big amounts of text:
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行后,我收到此错误.
I receive this error after translating about 2-3k rows.
推荐答案
我有点想出了这个问题.我认为这与Google API的请求限制有关.
I kind of figured out the problem. I think that this is about Google API's request limit.
我通过在每次迭代中重新初始化翻译器API来解决了这个问题:
I solved this by reinitializing the translator API on every iteration:
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)
这篇关于GoogleTrans API错误-预期值:第1行第1列(字符0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文