From 165827beeb6d6ff87dd0761345ac92c1a6dfbfba Mon Sep 17 00:00:00 2001 From: Erik Dillingham Date: Mon, 2 Oct 2017 09:23:28 -0700 Subject: [PATCH 1/2] wrapped _send call in exception handler to account for garbage data per issue #12 --- cleverwrap/cleverwrap.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cleverwrap/cleverwrap.py b/cleverwrap/cleverwrap.py index a6209b8..738b409 100644 --- a/cleverwrap/cleverwrap.py +++ b/cleverwrap/cleverwrap.py @@ -68,14 +68,25 @@ def _send(self, params): :type params: dict Returns: dict """ - # Get a response - try: - r = requests.get(self.url, params=params) - # catch errors, print then exit. - except requests.exceptions.RequestException as e: - print(e) - return r.json() + # try a maximum of twice to get the response + retry = True + + while(retry): + try: + r = requests.get(self.url, params=params) + result = r.json() + retry = False + # catch errors, print then exit. + except requests.exceptions.RequestException as e: + print(e) + + except ValueError as err: + # account for issue #12 + self.reset() + retry = True + + return result def _process_reply(self, reply): """ take the cleverbot.com response and populate properties. """ From f27644bed4a53222e22fc0cef58ff31b97957d45 Mon Sep 17 00:00:00 2001 From: Erik Dillingham Date: Mon, 2 Oct 2017 09:37:41 -0700 Subject: [PATCH 2/2] updated ValueError retry block to prevent an infinite loop --- cleverwrap/cleverwrap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cleverwrap/cleverwrap.py b/cleverwrap/cleverwrap.py index 738b409..48c47bd 100644 --- a/cleverwrap/cleverwrap.py +++ b/cleverwrap/cleverwrap.py @@ -70,21 +70,21 @@ def _send(self, params): """ # try a maximum of twice to get the response - retry = True + retry, reset = True, False while(retry): + retry = False try: r = requests.get(self.url, params=params) result = r.json() - retry = False # catch errors, print then exit. except requests.exceptions.RequestException as e: print(e) - except ValueError as err: # account for issue #12 self.reset() - retry = True + if not reset: + reset = retry = True return result