From 43a25486ba2ce6fc1f2caaff58b6707a2757af6d Mon Sep 17 00:00:00 2001 From: Bart Geesink Date: Sat, 24 Jun 2017 17:41:40 +0200 Subject: [PATCH] [modules/getcrypto] Add error handling to the api request. This prevents a bumblebee crash when no internet connection is present (like when a laptop resumes from sleep mode) --- bumblebee/modules/getcrypto.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index 1f0aed7..f4565ba 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -17,6 +17,7 @@ import time import bumblebee.input import bumblebee.output import bumblebee.engine +from requests.exceptions import RequestException def getfromkrak(coin): if coin=='Btc': @@ -28,7 +29,12 @@ def getfromkrak(coin): if coin=='Ltc': epair = "ltcusd" tickname = "XLTCZUSD" - krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() + try: + krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() + except RequestException: + return "No connection" + except Exception: + return "No connection" kethusdask = float(krakenget['result'][tickname]['a'][0]) kethusdbid = float(krakenget['result'][tickname]['b'][0]) return coin+": "+str((kethusdask+kethusdbid)/2)[0:6]