|
3 | 3 | from json import loads
|
4 | 4 |
|
5 | 5 | from requests import Response, Session
|
| 6 | +from requests.auth import HTTPBasicAuth |
6 | 7 | from tenacity import retry, stop_after_attempt
|
7 | 8 | from pandas import DataFrame
|
8 | 9 |
|
|
19 | 20 | from ._endpoints import AEpiDataEndpoints
|
20 | 21 | from ._constants import HTTP_HEADERS, BASE_URL
|
21 | 22 | from ._covidcast import CovidcastDataSources, define_covidcast_fields
|
| 23 | +from ._auth import get_api_key |
22 | 24 |
|
23 | 25 |
|
24 | 26 | @retry(reraise=True, stop=stop_after_attempt(2))
|
25 | 27 | def _request_with_retry(
|
26 | 28 | url: str, params: Mapping[str, str], session: Optional[Session] = None, stream: bool = False
|
27 | 29 | ) -> Response:
|
28 | 30 | """Make request with a retry if an exception is thrown."""
|
| 31 | + basic_auth = HTTPBasicAuth("epidata", get_api_key()) |
29 | 32 |
|
30 | 33 | def call_impl(s: Session) -> Response:
|
31 |
| - res = s.get(url, params=params, headers=HTTP_HEADERS, stream=stream) |
| 34 | + res = s.get(url, params=params, headers=HTTP_HEADERS, stream=stream, auth=basic_auth) |
32 | 35 | if res.status_code == 414:
|
33 |
| - return s.post(url, params=params, headers=HTTP_HEADERS, stream=stream) |
| 36 | + return s.post(url, params=params, headers=HTTP_HEADERS, stream=stream, auth=basic_auth) |
34 | 37 | return res
|
35 | 38 |
|
36 | 39 | if session:
|
|
0 commit comments