Python Google Translate API错误 [英] Python Google Translate API error

查看:268
本文介绍了Python Google Translate API错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对python很陌生,并尝试使用Google API翻译一堆关键字.我有一个包含3000个关键字的excel文件,这些关键字混合了英语,西班牙语,德语等.试图将所有内容翻译成英语.

I am very to new to python and trying to translate a bunch of keywords using google API. I have an excel file with 3000 keywords which are mix of english, spanish, german etc. Trying to translate everything to English.

但是,每次我运行代码时,在不同的值下都会出现错误.有时,我的代码在第810个关键字处给出错误,而有时它在1038个关键字处给出错误. 而且我什至没有编辑文件的布局.

However, every time I run my code, I get error at different values. Sometimes, my code give error at 810th keyword while sometime it gives error at 1038 keyword. And I am not even editing the layout of the file.

JSONDecodeError:预期值:第1行第1列(字符0)

下面是我的代码:

from googletrans import Translator
import pandas
import math
import time
df = pandas.read_excel(r'Desktop/python_keywords.xlsx')
keywords = df['Keywords']
Translate = []
translator = Translator()

for i in range(0,len(keywords)):
    word = translator.translate(str(keywords[j])).text
    Translate.append(word)

推荐答案

通常,此错误是由于Googletrans API中的字符数限制为15K所致.

Normally this error is due to the character limit of 15K in Googletrans API.

JSONDecodeError:期望值:第1行第1列(字符0)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

请考虑减少字符数.

这篇关于Python Google Translate API错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆