Skip to content

Commit

Permalink
Added a num_retry keyword argument to iris.data.urls_hek().
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Feb 3, 2024
1 parent f737e82 commit 8f7e4a4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions iris/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def urls_hek(
spectrograph: bool = True,
sji: bool = True,
deconvolved: bool = False,
num_retry: int = 5,
) -> list[urlpath.URL]:
"""
Find a list of URLs to download matching the given parameters.
Expand Down Expand Up @@ -121,6 +122,8 @@ def urls_hek(
deconvolved
Boolean flag controlling whether to include the deconvolved slitjaw
imagery. Has no effect if ``sji`` is :obj:`False`.
num_retry
The number of times to try to connect to the server.
Examples
--------
Expand Down Expand Up @@ -148,12 +151,14 @@ def urls_hek(
limit=limit,
)

response = None
while response is None:
for i in range(num_retry):
try:
response = requests.get(query, timeout=5).json()
break
except requests.exceptions.RequestException: # pragma: no cover
pass
else:
raise ConnectionError(f"Could not get query {query}")

result = []
for event in response["Events"]:
Expand Down

0 comments on commit 8f7e4a4

Please sign in to comment.