Python Google Translate API error

前端 未结 2 1164
春和景丽
春和景丽 2020-12-21 08:39

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 et

2条回答
  •  猫巷女王i
    2020-12-21 09:35

    Which line of your code gives you this error? Look at error trace
    Let's start with your iterators: it is declared as i, but then you use j. Then check length of your request. It shouldn't be longer than 5k symbols according to JSONDecodeError using Google Translate API with Python3.
    Anyway, it looks like api responds with empty json and you have to add at least try .. except to avoid this error, smth like this:

    try:  
        word = translator.translate(str(keywords[j])).text  
    except JSONDecodeError as err:  
        print(err)  # if you want to see when error happens
    else:
        Translate.append(word)
    

提交回复
热议问题