Skip to content

resolve issue #867 by explicitly adding headers to url _get_response #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions pandas_datareader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class _BaseReader(object):
_format = "string"

def __init__(
self,
symbols,
start=None,
end=None,
retry_count=3,
pause=0.1,
timeout=30,
session=None,
freq=None,
self,
symbols,
start=None,
end=None,
retry_count=3,
pause=0.1,
timeout=30,
session=None,
freq=None,
):

self.symbols = symbols
Expand Down Expand Up @@ -149,6 +149,9 @@ def _get_response(self, url, params=None, headers=None):
"""

# initial attempt + retry
if headers == None:
headers = self.headers

pause = self.pause
last_response_text = ""
for _ in range(self.retry_count + 1):
Expand Down Expand Up @@ -224,14 +227,14 @@ class _DailyBaseReader(_BaseReader):
""" Base class for Google / Yahoo daily reader """

def __init__(
self,
symbols=None,
start=None,
end=None,
retry_count=3,
pause=0.1,
session=None,
chunksize=25,
self,
symbols=None,
start=None,
end=None,
retry_count=3,
pause=0.1,
session=None,
chunksize=25,
):
super(_DailyBaseReader, self).__init__(
symbols=symbols,
Expand Down Expand Up @@ -297,7 +300,7 @@ def _in_chunks(seq, size):
"""
Return sequence in 'chunks' of size defined by size
"""
return (seq[pos : pos + size] for pos in range(0, len(seq), size))
return (seq[pos: pos + size] for pos in range(0, len(seq), size))


class _OptionBaseReader(_BaseReader):
Expand Down Expand Up @@ -331,7 +334,7 @@ def get_put_data(self, month=None, year=None, expiry=None):
raise NotImplementedError

def get_near_stock_price(
self, above_below=2, call=True, put=False, month=None, year=None, expiry=None
self, above_below=2, call=True, put=False, month=None, year=None, expiry=None
):
"""
***Experimental***
Expand All @@ -340,7 +343,7 @@ def get_near_stock_price(
raise NotImplementedError

def get_forward_data(
self, months, call=True, put=False, near=False, above_below=2
self, months, call=True, put=False, near=False, above_below=2
): # pragma: no cover
"""
***Experimental***
Expand Down
2 changes: 1 addition & 1 deletion pandas_datareader/yahoo/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _read_one_data(self, url, params):
del params["symbol"]
url = url.format(symbol)

resp = self._get_response(url, params=params)
resp = self._get_response(url, params=params, headers=self.headers)
ptrn = r"root\.App\.main = (.*?);\n}\(this\)\);"
try:
j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
Expand Down