From 6d9f04355cbde05d9bd2d5e1f11b5b0a3c627dcd Mon Sep 17 00:00:00 2001 From: Michal Siedlaczek Date: Wed, 4 Oct 2017 10:06:14 -0400 Subject: [PATCH] Strip JSON response from Google API of the 5-byte prefix Read more here: * https://github.com/google/gitiles/issues/22 * https://github.com/google/gitiles/issues/82 --- scripts/install_dict.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/install_dict.py b/scripts/install_dict.py index 13839d150..9590d07d8 100755 --- a/scripts/install_dict.py +++ b/scripts/install_dict.py @@ -89,8 +89,11 @@ def language_list_from_api(): """Return a JSON with a list of available languages from Google API.""" listurl = urllib.parse.urljoin(API_URL, '?format=JSON') response = urllib.request.urlopen(listurl) - # TODO: what's up with the first 4 characters? - entries = json.loads(response.read().decode('utf-8')[4:])['entries'] + # A special 5-byte prefix must be stripped from the response content + # See: https://github.com/google/gitiles/issues/22 + # https://github.com/google/gitiles/issues/82 + json_content = response.read()[5:] + entries = json.loads(json_content.decode('utf-8'))['entries'] return entries