Show error message elegantly

This commit is contained in:
PCoder 2019-08-13 14:59:12 +05:30
parent 3e6d535a74
commit c3c9ba4a72
1 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import urllib.request
import json
import sys
from pyotp import TOTP
UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch"
@ -45,6 +46,13 @@ class ungleichPay(object):
"token": TOTP(args.seed).now(),
"Accept": "application/json"
})
response = urllib.request.urlopen(req)
try:
response = urllib.request.urlopen(req)
except urllib.error.HTTPError as err:
print(str(err))
sys.exit(1)
except urllib.error.URLError as uerr:
print(str(uerr))
sys.exit(2)
response_json = json.loads(response.read().decode('utf-8'))
print(response_json["data"])