Skip to content

Commit

Permalink
oddily ncCF datasets cannot be quoted
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Sep 19, 2024
1 parent 858218b commit 408ce1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

def quote_url(url: str) -> str:
"""Quote URL args for modern ERDDAP servers."""
# We should always quote for queries.
if "?" in url and "/erddap/search/" not in url:
# No idea why csv must be quoted in 2.23 but ncCF doesn't :-/
do_not_quote = ["/erddap/search/", "ncCF"]
if any(True for string in do_not_quote if string in url):
return url
# We should always quote some queries.
if "?" in url:
base, unquoted = url.split("?")
url = f"{base}?{parse.quote_plus(unquoted)}"
return url
Expand Down
13 changes: 13 additions & 0 deletions tests/test_to_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ def test_to_xarray_tabledap(dataset_tabledap):
assert ds["temperature"].name == "temperature"


@pytest.mark.web
def test_to_xarray_cannot_be_quoted():
"""Test dataset that failed when quoted."""
e = ERDDAP(server="https://erddap.aoos.org/erddap/", protocol="tabledap")
e.dataset_id = "kotzebue-alaska-water-level"
e.constraints = {
"time>=": "2018-09-05T21:00:00Z",
"time<=": "2019-07-10T19:00:00Z",
}
ds = e.to_xarray()
assert isinstance(ds, xr.Dataset)


@pytest.mark.web
def test_to_xarray_requests_kwargs(dataset_tabledap):
"""Test converting tabledap to an xarray Dataset with manual timeout."""
Expand Down

0 comments on commit 408ce1a

Please sign in to comment.