From 4cd99f2a9cf39dec46c6477e61789f1e706c9744 Mon Sep 17 00:00:00 2001 From: milaq Date: Tue, 20 Aug 2019 23:43:32 +0200 Subject: [PATCH] Radiobrowser: Handle connection errors --- ycast/radiobrowser.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ycast/radiobrowser.py b/ycast/radiobrowser.py index 3daa0e0..d155c69 100644 --- a/ycast/radiobrowser.py +++ b/ycast/radiobrowser.py @@ -41,9 +41,13 @@ class Station: def request(url): logging.debug("Radiobrowser API request: %s", url) headers = {'content-type': 'application/json', 'User-Agent': generic.USER_AGENT + '/' + __version__} - response = requests.get('http://www.radio-browser.info/webservice/json/' + url, headers=headers) + try: + response = requests.get('http://www.radio-browser.info/webservice/json/' + url, headers=headers) + except requests.exceptions.ConnectionError as err: + logging.error("Connection to Radiobrowser API failed (%s)", err) + return {} if response.status_code != 200: - logging.error("Could not fetch data from Radiobrowser (%s)", response.status_code) + logging.error("Could not fetch data from Radiobrowser API (HTML status %s)", response.status_code) return {} return response.json()