From 8d4e81e33e977e1217838a926e5856e85f6eb2da Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 31 Mar 2016 00:10:46 +0200 Subject: [PATCH] Catch JSON decoding errors --- velib.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/velib.py b/velib.py index cff29b7..eea2578 100755 --- a/velib.py +++ b/velib.py @@ -4,6 +4,7 @@ from config import * import json import requests import sqlite3 +import sys import time @@ -52,7 +53,10 @@ def retrieve_stations(): r = requests.get(api_endpoint, params={"apiKey": api_key, "contract": contract}) # Handle the JSON response - stations_list_json = json.loads(r.text) + try: + stations_list_json = json.loads(r.text) + except ValueError: + sys.exit("Got invalid JSON payload:\n" + r.text) stations_list = [] for station in stations_list_json: stations_list.append(station)