|
29 | 29 | import json |
30 | 30 | import logging |
31 | 31 | import numbers |
32 | | -import os |
33 | 32 | import re |
34 | 33 | from collections.abc import ( |
35 | 34 | AsyncIterator, |
|
49 | 48 | import pandas as pd |
50 | 49 | from anyio.from_thread import start_blocking_portal |
51 | 50 |
|
52 | | -from dataretrieval import __version__ |
53 | 51 | from dataretrieval.exceptions import DataRetrievalError |
54 | 52 | from dataretrieval.ogc import chunking |
55 | 53 | from dataretrieval.ogc import progress as _progress |
|
61 | 59 | from dataretrieval.ogc.errors import _paginated_failure_message, _raise_for_non_200 |
62 | 60 | from dataretrieval.ogc.planning import _safe_elapsed |
63 | 61 | from dataretrieval.ogc.shaping import GEOPANDAS, _finalize_ogc, _get_resp_data |
64 | | -from dataretrieval.utils import HTTPX_DEFAULTS, BaseMetadata, _get, _network_error |
| 62 | +from dataretrieval.utils import ( |
| 63 | + HTTPX_DEFAULTS, |
| 64 | + BaseMetadata, |
| 65 | + _default_headers, |
| 66 | + _get, |
| 67 | + _network_error, |
| 68 | +) |
65 | 69 |
|
66 | 70 | # Set up logger for this module |
67 | 71 | logger = logging.getLogger(__name__) |
@@ -242,29 +246,6 @@ def _cql2_param(args: dict[str, Any]) -> str: |
242 | 246 | return json.dumps(query, separators=(",", ":")) |
243 | 247 |
|
244 | 248 |
|
245 | | -def _default_headers() -> dict[str, str]: |
246 | | - """ |
247 | | - Generate default HTTP headers for API requests. |
248 | | -
|
249 | | - Returns |
250 | | - ------- |
251 | | - dict |
252 | | - A dictionary containing default headers including 'Accept-Encoding', |
253 | | - 'Accept', 'User-Agent', and 'lang'. If the environment variable |
254 | | - 'API_USGS_PAT' is set, its value is included as the 'X-Api-Key' header. |
255 | | - """ |
256 | | - headers = { |
257 | | - "Accept-Encoding": "compress, gzip", |
258 | | - "Accept": "application/json", |
259 | | - "User-Agent": f"python-dataretrieval/{__version__}", |
260 | | - "lang": "en-US", |
261 | | - } |
262 | | - token = os.getenv("API_USGS_PAT") |
263 | | - if token: |
264 | | - headers["X-Api-Key"] = token |
265 | | - return headers |
266 | | - |
267 | | - |
268 | 249 | def _check_ogc_requests(endpoint: str, req_type: str = "queryables") -> dict[str, Any]: |
269 | 250 | """ |
270 | 251 | Sends an HTTP GET request to the specified OGC endpoint and request type, |
|
0 commit comments