Skip to content

Commit 6031a2e

Browse files
committed
Retry read errors spherex_intro.md
1 parent 57bc10d commit 6031a2e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

tutorials/spherex/spherex_intro.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ The following packages must be installed to run this notebook.
6060
## 4. Imports
6161

6262
```{code-cell} ipython3
63+
import http.client
64+
import time
65+
import urllib.error
66+
6367
import numpy as np
6468
import matplotlib.pyplot as plt
6569
@@ -155,7 +159,16 @@ You can put this URL into a browser to download the file. Or you can work with i
155159
Use Astropy to examine the header of the URL from the previous step.
156160

157161
```{code-cell} ipython3
158-
hdulist = fits.open(spectral_image_url)
162+
Max number of times to retry HTTP errors.
163+
max_retries = 3
164+
for attempt in range(max_retries):
165+
try:
166+
hdulist = fits.open(spectral_image_url)
167+
break
168+
except (urllib.error.HTTPError, http.client.IncompleteRead):
169+
if attempt == max_retries - 1:
170+
raise
171+
time.sleep(10 * (attempt + 1))
159172
hdulist.info()
160173
```
161174

0 commit comments

Comments
 (0)