Skip to content

Commit 79ac648

Browse files
author
brentru
committed
add advanced test
1 parent 0501bf5 commit 79ac648

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

examples/requests_advanced_ethernet.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@
1616

1717
JSON_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.
2024
headers = {"user-agent" : "blinka/1.0.0"}
2125

2226
print("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
2438
print('-'*60)
2539

2640
json_data = response.json()

0 commit comments

Comments
 (0)