Radiobrowser: Handle connection errors

This commit is contained in:
milaq 2019-08-20 23:43:32 +02:00
parent 048e479080
commit 4cd99f2a9c

View file

@ -41,9 +41,13 @@ class Station:
def request(url): def request(url):
logging.debug("Radiobrowser API request: %s", url) logging.debug("Radiobrowser API request: %s", url)
headers = {'content-type': 'application/json', 'User-Agent': generic.USER_AGENT + '/' + __version__} 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: 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 {}
return response.json() return response.json()