Handle network exceptions

This commit is contained in:
2017-11-18 14:58:46 +00:00
parent 81dae53d65
commit 21866c38a5
3 changed files with 16 additions and 14 deletions

View File

@@ -2,7 +2,9 @@
import requests
r = requests.get('https://blockchain.info/ticker');
ticker = r.json()
print('£%.2f' % float(ticker['GBP']['sell']))
try:
r = requests.get('https://blockchain.info/ticker');
ticker = r.json()
print('£%.2f' % float(ticker['GBP']['sell']))
except requests.exceptions.RequestException as e:
sys.exit(1)