1

I'm trying to translate a column of Chinese addresses into English. I followed the documentation here: new column with coordinates using geopy pandas. It worked the first time (about 30 minutes ago). All of a sudden, when I re-ran it, it threw me an error. Doesn't matter I restart the kernel, it does not work now. Does anyone know what is going on? How do I solve this? Thanks in advance!

Sample df (edit request from Zaraki Kenpachi)

Full Chinese Address 
湖北省荆州市洪湖市洪湖经济开发区万家墩大道1号
江西省九江市共青城工业新区
湖北孝感市孝南区毛陈镇孝武大道198号

Code

from googletrans import Translator

translator = Translator()

df['Translated English Address'] = df['Full Chinese Address'].apply(translator.translate, src='zh-CN', dest='en').apply(getattr, args=('text',))

# df= xin_loc.dropna(subset=['Translated English Address'])

df.head()

Error

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Matthias Gallagher
  • 475
  • 1
  • 7
  • 20
  • i get proper response from you code with basic Chinese example. Can you post few lines of china addresses where you got errors? – Zaraki Kenpachi Sep 17 '20 at 06:22
  • Hello Zaraki, Thanks for your reply. This code translated the address the first time I ran it but when I re-ran it, it gave me this error. I have tried restarted kernel a few times and it simply doesn't work like the first time anymore. Anyhow, here is the edited sample Chinese addresses. – Matthias Gallagher Sep 17 '20 at 06:27
  • I have tested posted addresses and all of them seems to be working well: `No. 1, Wanjiadun Avenue, Honghu Economic Devel...`, `Gongqingcheng Industrial Zone, Jiujiang City, ..`, `198 Xiaowu Avenue, Maochen Town, Xiaonan Distr...` – Zaraki Kenpachi Sep 17 '20 at 06:28
  • Thanks again, Zaraki. Yes, the code worked well the first time I ran it too. But after about 30 minutes, I re-ran it and it gave me the error. That is why I'm posting the question. – Matthias Gallagher Sep 17 '20 at 06:33
  • try to set `encoding` while reading from csv data file. `encoding="GBK"` – Zaraki Kenpachi Sep 17 '20 at 06:36
  • Thanks, Zaraki. I'm currently doing a pd.read_excel(). How do I reset the encoding? – Matthias Gallagher Sep 17 '20 at 06:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221614/discussion-between-zaraki-kenpachi-and-matthias-gallagher). – Zaraki Kenpachi Sep 17 '20 at 06:42

1 Answers1

0

I eventually solved this problem by turning on a VPN. Apparently this Google translate API has an unannounced daily limit. It blocks your IP address once you exceed the daily limit.

Matthias Gallagher
  • 475
  • 1
  • 7
  • 20