Skip to content

Commit 8030d0a

Browse files
committed
Retry on a failed API call.
In the UI, we often need to click "Analyze" just one more time before we get a 200 response. Adding the logic to make that additional call automatically on error.
1 parent 36d7902 commit 8030d0a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

isthisstockgood/DataFetcher.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import isthisstockgood.RuleOneInvestingCalculations as RuleOne
44
from requests_futures.sessions import FuturesSession
5+
from requests.adapters import HTTPAdapter, Retry
56
from isthisstockgood.Active.MSNMoney import MSNMoney
67
from isthisstockgood.Active.YahooFinance import YahooFinanceAnalysis
78
from isthisstockgood.Active.Zacks import Zacks
@@ -147,6 +148,16 @@ def _create_session(self):
147148
session.headers.update({
148149
'User-Agent' : random.choice(DataFetcher.USER_AGENT_LIST)
149150
})
151+
152+
retries = Retry(
153+
total=3,
154+
backoff_factor=0.1,
155+
status_forcelist=[301]
156+
)
157+
adapter = HTTPAdapter(max_retries=retries)
158+
session.mount('http://', adapter)
159+
session.mount('https://', adapter)
160+
150161
return session
151162

152163
def fetch_msn_money_data(self):

0 commit comments

Comments
 (0)