File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1616
1717JSON_GET_URL = "http://httpbin.org/get"
1818
19+ attempts = 3 # Number of attempts to retry each request
20+ failure_count = 0
21+ response = None
22+
1923# Define a custom header as a dict.
2024headers = {"user-agent" : "blinka/1.0.0" }
2125
2226print ("Fetching JSON data from %s..." % JSON_GET_URL )
23- response = requests .get (JSON_GET_URL , headers = headers )
27+ while not response :
28+ try :
29+ response = requests .get (JSON_GET_URL , headers = headers )
30+ attempts = 0
31+ except AssertionError as error :
32+ print ("Request failed, retrying...\n " , error )
33+ failure_count += 1
34+ if failure_count >= attempts :
35+ raise AssertionError ("Failed to resolve hostname, \
36+ please check your router's DNS configuration." )
37+ continue
2438print ('-' * 60 )
2539
2640json_data = response .json ()
You can’t perform that action at this time.
0 commit comments