Show error message elegantly
This commit is contained in:
parent
3e6d535a74
commit
c3c9ba4a72
1 changed files with 9 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from pyotp import TOTP
|
from pyotp import TOTP
|
||||||
|
|
||||||
UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch"
|
UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch"
|
||||||
|
@ -45,6 +46,13 @@ class ungleichPay(object):
|
||||||
"token": TOTP(args.seed).now(),
|
"token": TOTP(args.seed).now(),
|
||||||
"Accept": "application/json"
|
"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'))
|
response_json = json.loads(response.read().decode('utf-8'))
|
||||||
print(response_json["data"])
|
print(response_json["data"])
|
||||||
|
|
Loading…
Reference in a new issue