Skip to content

Commit

Permalink
Refactored session management system to handle cookie and crumbs better.
Browse files Browse the repository at this point in the history
Added fixes for #167, #166, #160.
  • Loading branch information
connorsanders committed Dec 13, 2023
1 parent a5da5a7 commit 80e4e21
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions yahoofinancials/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,18 @@ def _request_handler(self, url, res_field=""):
open_session = False
session, crumb = _init_session(None, proxies=self._get_proxy(), timeout=self.timeout)
crumb_url = cur_url + "&crumb=" + str(crumb)
response = urlopener.get_data(session, crumb_url, proxy=self._get_proxy(), timeout=self.timeout)
try:
response = urlopener.get_data(session, crumb_url, proxy=self._get_proxy(), timeout=self.timeout)
except:
continue
else:
response = urlopener.open(cur_url, proxy=self._get_proxy(), timeout=self.timeout)
if response.status_code == 401:
try:
response = urlopener.open(cur_url, proxy=self._get_proxy(), timeout=self.timeout)
if response.status_code == 401:
open_session = True
except AttributeError:
open_session = True
continue
if response.status_code != 200:
time.sleep(random.randrange(1, 5))
response.close()
Expand Down

0 comments on commit 80e4e21

Please sign in to comment.