Python Google Translate API error

Python Google Translate API error … here is a solution to the problem.

Python Google Translate API error

I’m new to python and trying to translate a bunch of keywords using the google API. I have an excel file with 3000 keywords that mix English, Spanish, German, etc. Tried to translate everything into English.

However, every time I run my code, I get an error on a different value. Sometimes, my code gives an error at the 810th keyword, while sometimes it gives an error at the 1038th keyword.
And I didn’t even edit the layout of the file.

JSONDecodeError: Expected value: row 1, column 1 (character 0).

Here’s my code:

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)

Solution

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

JSONDecodeError: Expected value: row 1, column 1 (character 0).

Consider reducing the number of characters.

Related Problems and Solutions