Skip to content

Commit

Permalink
[Fix] Add session in yahoo source
Browse files Browse the repository at this point in the history
  • Loading branch information
ileodo committed Jul 3, 2023
1 parent 2122268 commit e365729
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion beanprice/sources/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ def get_price_series(ticker: str,

if requests is None:
raise YahooError("You must install the 'requests' library.")


session = requests.Session()
session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0'})
session.get('https://fc.yahoo.com') # This populates the correct cookies in the session


url = "https://query1.finance.yahoo.com/v8/finance/chart/{}".format(ticker)
payload: Dict[str, Union[int, str]] = {
'period1': int(time_begin.timestamp()),
'period2': int(time_end.timestamp()),
'interval': '1d',
}
payload.update(_DEFAULT_PARAMS)
response = requests.get(url, params=payload, headers={'User-Agent': None})
response = session.get(url, params=payload)
result = parse_response(response)

meta = result['meta']
Expand Down

0 comments on commit e365729

Please sign in to comment.