Skip to content

Commit

Permalink
Raise for status when Yahoo! returns 403
Browse files Browse the repository at this point in the history
Sometimes Yahoo! returns 403.  This causes a tuple destructuring error later in `parse_response()`, when `.json()` actually does not return anything that can be destructured.

The correct defensive behavior is to fail fast and exit here.
  • Loading branch information
Rudd-O authored Feb 22, 2023
1 parent b761102 commit 06bc6fa
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions beanprice/sources/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def get_price_series(ticker: str,
}
payload.update(_DEFAULT_PARAMS)
response = requests.get(url, params=payload, headers={'User-Agent': None})
response.raise_for_status()
result = parse_response(response)

meta = result['meta']
Expand Down Expand Up @@ -121,6 +122,7 @@ def get_latest_price(self, ticker: str) -> Optional[source.SourcePrice]:
}
payload.update(_DEFAULT_PARAMS)
response = requests.get(url, params=payload, headers={'User-Agent': None})
response.raise_for_status()
try:
result = parse_response(response)
except YahooError as error:
Expand Down

0 comments on commit 06bc6fa

Please sign in to comment.