[weboob] Patch for boobank, error handling in budgea

Guyzmo guyzmo+weboob at m0g.net
Tue May 3 19:12:02 CEST 2016


Attached a patch for bad error handling in boobank/budgea
-------------- next part --------------
>From df2e66fdcfec5fab34e9472d1804122f38e74a45 Mon Sep 17 00:00:00 2001
From: Bernard `Guyzmo` Pratz <guyzmo+github at m0g.net>
Date: Tue, 3 May 2016 19:06:53 +0200
Subject: [PATCH] Fixed issue with the budgea action of the boobank application

- error parsing was leading to KeyError when the message key was missing ;
- switched to much better .get() method of python's dict to avoid the exception ;
- also updated to more modern and elegant .format() method.

Signed-off-by: Bernard `Guyzmo` Pratz <guyzmo+github at m0g.net>
---
 weboob/applications/boobank/boobank.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py
index fd8e154..52b1e87 100644
--- a/weboob/applications/boobank/boobank.py
+++ b/weboob/applications/boobank/boobank.py
@@ -533,7 +533,7 @@ class Boobank(ReplApplication):
             r = client.request('auth/token', data={'username': username, 'password': password, 'application': 'weboob'})
         except BrowserHTTPError as r:
             error = r.response.json()
-            print('Error: %s' % (error['message'] or error['code']), file=self.stderr)
+            print('Error: {}'.format(error.get('message', error['code'])), file=self.stderr)
             return 1
 
         client.session.headers['Authorization'] = 'Bearer %s' % r['token']
-- 
2.8.0



More information about the weboob mailing list