Skip to content

Commit 9c1d506

Browse files
committed
Replacement regex logic for additional Yahoo cookie token structures, per chris-b1
1 parent 683ab75 commit 9c1d506

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

pandas_datareader/yahoo/daily.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,10 @@ def _get_crumb(self, retries):
154154
params=self.params, headers=self.headers)
155155
out = str(self._sanitize_response(response))
156156
# Matches: {"crumb":"AlphaNumeric"}
157-
regex = re.search(r'"crumb" ?: ?"([A-Za-z0-9.\\]{11,})"', out)
158-
159-
if regex is not None:
160-
crumbs = regex.groups()
161-
crumb = re.sub(r'\\', '', crumbs[0])
162-
return crumb
163-
elif retries > 0:
164-
# It is possible we hit a 401 with frequent requests. Cool-off:
165-
time.sleep(2)
166-
retries -= 1
167-
return self._get_crumb(retries)
168-
else:
169-
raise OSError("Unable to retrieve Yahoo breadcrumb, exiting.")
157+
rpat = '"CrumbStore":{"crumb":"([^"]+)"}'
158+
159+
crumb = re.findall(rpat, out)[0]
160+
return crumb.encode('ascii').decode('unicode-escape')
170161

171162

172163
def _adjust_prices(hist_data, price_list=None):

0 commit comments

Comments
 (0)