gpt4 book ai didi

python - GoogleTrans API 错误 - 预期值 : line 1 column 1 (char 0)

转载 作者:太空狗 更新时间:2023-10-29 19:33:31 25 4
gpt4 key购买 nike

我在一次迭代中翻译数千个文本数据时遇到此错误:

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 - GoogleTrans API 错误 - 预期值 : line 1 column 1 (char 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49497391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com