Skip to content

Commit fd0336f

Browse files
committed
Add retry/pause Logic to EnigmaReader
1 parent a4f42bf commit fd0336f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

pandas_datareader/enigma.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
2-
from pandas.compat import StringIO
2+
import time
33

4+
from pandas.compat import StringIO
45
import pandas.compat as compat
56
import pandas as pd
67

@@ -66,6 +67,8 @@ def __init__(self,
6667
}
6768
self.session.headers.update(headers)
6869
self._base_url = "https://public.enigma.com/api"
70+
self._retry_count = retry_count
71+
self._retry_delay = pause
6972

7073
def read(self):
7174
try:
@@ -80,11 +83,21 @@ def _read(self):
8083
return pd.read_csv(StringIO(decoded_data))
8184

8285
def _get(self, url):
83-
"""HTTP GET Request"""
86+
"""HTTP GET Request with Retry Logic"""
8487
url = "{0}/{1}".format(self._base_url, url)
85-
response = self.session.get(url)
86-
response.raise_for_status()
87-
return response
88+
attempts = 0
89+
while True:
90+
try:
91+
response = self.session.get(url)
92+
response.raise_for_status()
93+
return response
94+
except Exception as e:
95+
if attempts < self._retry_count:
96+
attempts += 1
97+
time.sleep(self._retry_delay)
98+
continue
99+
else:
100+
raise e
88101

89102
def get_current_snapshot_id(self):
90103
"""Get ID of the most current snapshot of a dataset"""

0 commit comments

Comments
 (0)