Skip to content

Commit

Permalink
Fixed Issue tristantao#27. Also added some explicit declarations incl…
Browse files Browse the repository at this point in the history
…uding: explicit default val for `json_result` & a py3-compat rawstring error.
  • Loading branch information
rtruxal committed Sep 6, 2017
1 parent 8f4b10d commit c8cfa5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ dist_backup
#sensitive info in this driver
driver.py
secrets.cfg

#Pycharm IDE Config Files
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_json_results(self, response):
'''
Parses the request result and returns the JSON object. Handles all errors.
'''
json_results = None # <-- b/c PEP & to prevent weak-warnings while linting
try:
# return the proper JSON object, or error code if request didn't go through.
self.most_recent_json = response.json()
Expand All @@ -49,7 +50,7 @@ def get_json_results(self, response):
message = json_results['message']
try:
# extract time out seconds from response
timeout = int(re.search('in (.+?) seconds', message).group(1)) + 1
timeout = int(re.search(r'in (.+?) seconds', message).group(1)) + 1 # <--explicit rawstring for py3 compatibility.
print ("CODE 429, sleeping for {timeout} seconds").format(timeout=str(timeout))
time.sleep(timeout)
except (AttributeError, ValueError) as e:
Expand All @@ -60,9 +61,9 @@ def get_json_results(self, response):
time.sleep(5)
except ValueError as vE:
if not self.silent_fail:
raise PyMsCognitiveWebSearchException("Request returned with code %s, error msg: %s" % (r.status_code, r.text))
raise PyMsCognitiveWebSearchException("Request returned with code {}, error msg: {}".format(response.status_code, (response.text if response.text else "(no msg returned from server)")))
else:
print ("[ERROR] Request returned with code %s, error msg: %s. \nContinuing in 5 seconds." % (r.status_code, r.text))
print ("[ERROR] Request returned with code {}, error msg: {}. \nContinuing in 5 seconds.".format(response.status_code, (response.text if response.text else "(no msg returned from server)")))
time.sleep(5)
return json_results

Expand Down

0 comments on commit c8cfa5e

Please sign in to comment.