From 8448a83aba82379be96b135a835572ac2853665a Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sat, 9 Nov 2013 13:24:04 +0000 Subject: [PATCH] Update example so it works under Python 3. --- demo/example.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/demo/example.py b/demo/example.py index 1d204c5..523ea71 100644 --- a/demo/example.py +++ b/demo/example.py @@ -1,6 +1,11 @@ import sys + from yubico_client import Yubico from yubico_client import yubico_exceptions +from yubico_client.py3 import PY3 + +if PY3: + raw_input = input client_id = raw_input('Enter your client id: ') secret_key = raw_input('Enter your secret key (optional): ') @@ -19,17 +24,20 @@ try: status = client.verify(token) -except yubico_exceptions.InvalidClientIdError, e: - print 'Client with id %s does not exist' % (e.client_id) +except yubico_exceptions.InvalidClientIdError: + e = sys.exc_info()[1] + print('Client with id %s does not exist' % (e.client_id)) sys.exit(1) except yubico_exceptions.SignatureVerificationError: - print 'Signature verification failed' + print('Signature verification failed') sys.exit(1) -except yubico_exceptions.StatusCodeError, e: - print 'Negative status code was returned: %s' % (e.status_code) +except yubico_exceptions.StatusCodeError: + e = sys.exc_info()[1] + print('Negative status code was returned: %s' % (e.status_code)) sys.exit(1) if status: - print 'Success, the provided OTP is valid' + print('Success, the provided OTP is valid') else: - print 'No response from the servers or received other negative status code' + print('No response from the servers or received other negative ' + 'status code')