From e5ad5588ea2578412e1ccdf739e0d5e295afe74c Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Wed, 18 Sep 2024 21:32:01 +0200 Subject: [PATCH 1/2] update --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From dae2469aab69486b1f7544792d9681486ee64803 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Wed, 18 Sep 2024 21:33:58 +0200 Subject: [PATCH 2/2] Always quote params for modern ERDDAP servers --- erddapy/core/url.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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: