Skip to content

Commit b050829

Browse files
author
neil
committed
add retry
1 parent 7e0eb80 commit b050829

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

anyvm.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,21 @@ def get_free_vnc_display(bind_addr, start=0, end=100):
177177
return None
178178

179179
def fetch_url_content(url):
180-
req = Request(url)
181-
req.add_header('User-Agent', 'python-qemu-script')
182-
try:
183-
resp = urlopen(req)
184-
return resp.read().decode('utf-8')
185-
except Exception:
186-
return None
180+
attempts = 5
181+
for attempt in range(attempts):
182+
req = Request(url)
183+
req.add_header('User-Agent', 'python-qemu-script')
184+
try:
185+
resp = urlopen(req)
186+
return resp.read().decode('utf-8')
187+
except HTTPError as e:
188+
if e.code == 404:
189+
return None
190+
except Exception:
191+
pass
192+
if attempt < attempts - 1:
193+
time.sleep(3)
194+
return None
187195

188196
def download_file(url, dest):
189197
log("Downloading " + url)

0 commit comments

Comments
 (0)