Skip to content

wrapped _send call in exception handler to account for garbage data #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions cleverwrap/cleverwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down