diff --git a/cleverwrap/cleverwrap.py b/cleverwrap/cleverwrap.py index a6209b8..48c47bd 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, reset = True, False + + while(retry): + retry = False + try: + r = requests.get(self.url, params=params) + result = r.json() + # catch errors, print then exit. + except requests.exceptions.RequestException as e: + print(e) + except ValueError as err: + # account for issue #12 + self.reset() + if not reset: + reset = retry = True + + return result def _process_reply(self, reply): """ take the cleverbot.com response and populate properties. """