Catch JSON decoding errors
This commit is contained in:
parent
9849228ef1
commit
8d4e81e33e
4
velib.py
4
velib.py
@ -4,6 +4,7 @@ from config import *
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
@ -52,7 +53,10 @@ def retrieve_stations():
|
|||||||
r = requests.get(api_endpoint,
|
r = requests.get(api_endpoint,
|
||||||
params={"apiKey": api_key, "contract": contract})
|
params={"apiKey": api_key, "contract": contract})
|
||||||
# Handle the JSON response
|
# Handle the JSON response
|
||||||
|
try:
|
||||||
stations_list_json = json.loads(r.text)
|
stations_list_json = json.loads(r.text)
|
||||||
|
except ValueError:
|
||||||
|
sys.exit("Got invalid JSON payload:\n" + r.text)
|
||||||
stations_list = []
|
stations_list = []
|
||||||
for station in stations_list_json:
|
for station in stations_list_json:
|
||||||
stations_list.append(station)
|
stations_list.append(station)
|
||||||
|
Loading…
Reference in New Issue
Block a user