diff options
| author | André Doser <doser.andre@gmail.com> | 2015-01-27 23:03:52 +0100 |
|---|---|---|
| committer | André Doser <doser.andre@gmail.com> | 2015-01-27 23:03:52 +0100 |
| commit | 2fa9e819fce8556cb8fed744e6b5e29f178cbf9c (patch) | |
| tree | 380dad0d0b11d76b84ad8721e2baf2d21d0eae34 /py3status/modules | |
| parent | af7ee847d243d2a5d7a53fed2499ce45b9029522 (diff) | |
Error handling
Diffstat (limited to 'py3status/modules')
| -rw-r--r-- | py3status/modules/bitcoin-price.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/py3status/modules/bitcoin-price.py b/py3status/modules/bitcoin-price.py index a1bc2a6..53da320 100644 --- a/py3status/modules/bitcoin-price.py +++ b/py3status/modules/bitcoin-price.py @@ -55,13 +55,15 @@ class Py3status: response = {'full_text': '', 'name': 'bitcoin rates', 'cached_until': time() + self.cache_timeout} try: # python 3 - import urllib.request as ul - except: # python 2 - import urllib2 as ul + from urllib.request import urlopen + from urllib.error import URLError + except ImportError: # python 2 + from urllib2 import urlopen + from urllib2 import URLError # get the data from the bitcoincharts website try: - data = json.loads(ul.urlopen(self.url).read().decode()) - except Exception: + data = json.loads(urlopen(self.url).read().decode()) + except URLError: response['color'] = i3s_config['color_bad'] response['full_text'] = 'Bitcoincharts not reachable' return response @@ -74,7 +76,7 @@ class Py3status: rate = self._get_price(data, market, self.field) if i == self.color_index: # coloration color_rate = rate - except Exception: + except KeyError: continue out = market[:-3] if rate else market # market name out += ': ' |
