From 3e0a86c918a948479944168c61cac9d80ea29f86 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 4 Jul 2012 18:10:54 +0200 Subject: [PATCH] catch invalid response and show detailled error message --- eopayment/sips.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index f4dbddb..2dbbe87 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -114,10 +114,14 @@ class Payment(PaymentCommon): self.logger.debug('executing %s' % args) result,_ = subprocess.Popen(' '.join(args), stdout=subprocess.PIPE, shell=True).communicate() - if result[0] == '!': - result = result[1:] - if result[-1] == '!': - result = result[:-1] + try: + if result[0] == '!': + result = result[1:] + if result[-1] == '!': + result = result[:-1] + except IndexError: + raise ValueError("Invalid response", result) + return False result = result.split('!') self.logger.debug('got response %s' % result) return result