diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 905ebb2..c525c05 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,7 +50,7 @@ repos: - id: add-trailing-comma - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.3 + rev: v0.6.5 hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -73,7 +73,7 @@ repos: - id: nb-strip-paths - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.2.1 + rev: 2.2.4 hooks: - id: pyproject-fmt diff --git a/erddapy/core/url.py b/erddapy/core/url.py index 7acec64..a387666 100644 --- a/erddapy/core/url.py +++ b/erddapy/core/url.py @@ -23,6 +23,15 @@ OptionalList = list[str] | tuple[str] | None +def quote_url(url: str) -> str: + """Quote URL args for modern ERDDAP servers.""" + # We should always quote for queries. + if "?" in url and not "searchFor": + base, unquoted = url.split("?") + url = f"{base}?{parse.quote_plus(unquoted)}" + return url + + def _sort_url(url: str) -> str: """Return a URL with sorted variables and constraints for hashing.""" parts = parse.urlparse(url) @@ -48,7 +57,12 @@ def _sort_url(url: str) -> str: def _urlopen(url: str, auth: tuple | None = None, **kwargs: dict) -> BinaryIO: if "timeout" not in kwargs: kwargs["timeout"] = 60 - response = httpx.get(url, follow_redirects=True, auth=auth, **kwargs) + response = httpx.get( + quote_url(url), + follow_redirects=True, + auth=auth, + **kwargs, + ) try: response.raise_for_status() except httpx.HTTPError as err: