Catch JSON decoding errors

This commit is contained in:
Lucas Verney 2016-03-31 00:10:46 +02:00
parent 9849228ef1
commit 8d4e81e33e
1 changed files with 5 additions and 1 deletions

View File

@ -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)