Skip to content

Commit

Permalink
make connection retry up to 10 times if error
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmatrix62 committed Dec 22, 2017
1 parent d5e6ee3 commit f1a9b39
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions 2.1/service/oxford_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ def query(self, word):
:rtype: WebWord
"""
_qry_url = self._base_url + word
rsp = self.s.get(_qry_url, )
if rsp.status_code == 200:
return OxfordLearningDictWord(rsp.content.decode('utf-8'))

retried = 10
while retried:
try:
rsp = self.s.get(_qry_url, )
if rsp.status_code == 200:
return OxfordLearningDictWord(rsp.content.decode('utf-8'))
break
except:
retried -= 1
continue


def _get_single_dict(self, single_dict):
if not (self.cached(single_dict) and self.cache_result(single_dict)):
Expand Down

0 comments on commit f1a9b39

Please sign in to comment.