From d5e68abf95aa600232573234f5a8db86694bd106 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 13 Feb 2015 08:51:10 -0500 Subject: [PATCH] ENH: check badips.com response on presence of "categories" in it As https://travis-ci.org/fail2ban/fail2ban/jobs/50609529 query might fail in that response would not contain "categories". With this change we will handle it explicitly and will spit out ValueError, providing information about the response so it could be troubleshooted --- config/action.d/badips.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/config/action.d/badips.py b/config/action.d/badips.py index 250b1dc3..c2a239f5 100644 --- a/config/action.d/badips.py +++ b/config/action.d/badips.py @@ -111,6 +111,8 @@ class BadIPsAction(ActionBase): ------ HTTPError Any issues with badips.com request. + ValueError + If badips.com response didn't contain necessary information """ try: response = urlopen( @@ -122,7 +124,13 @@ class BadIPsAction(ActionBase): messages['err']) raise else: - categories = json.loads(response.read().decode('utf-8'))['categories'] + response_json = json.loads(response.read().decode('utf-8')) + if not 'categories' in response_json: + err = "badips.com response lacked categories specification. Response was: %s" \ + % (response_json,) + self._logSys.error(err) + raise ValueError(err) + categories = response_json['categories'] categories_names = set( value['Name'] for value in categories) if incParents: