Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ jobs:
python -m pip install -e . --no-deps --force-reinstall

- name: Full Tests
run: |
python -m pytest -rxs --cov=erddapy tests
run: >
pushd tests && python download_test_data.py && popd
&& python -m pytest -rxs --cov=erddapy tests
25 changes: 13 additions & 12 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from typing import BinaryIO
from urllib import parse

import httpx
import pytz
import requests
from pandas import to_datetime

OptionalStr = str | None
Expand Down Expand Up @@ -68,19 +68,19 @@ def _clean_response(response: str) -> str:

@functools.lru_cache(maxsize=128)
def _urlopen(url: str, auth: tuple | None = None, **kwargs: dict) -> BinaryIO:
if "timeout" not in kwargs:
kwargs["timeout"] = 60
response = httpx.get(
timeout = kwargs.pop("timeout", 60)
response = requests.get(
url,
follow_redirects=True,
allow_redirects=True,
auth=auth,
timeout=timeout,
**kwargs,
)
try:
response.raise_for_status()
except httpx.HTTPError as err:
except requests.HTTPError as err:
msg = str(response.content.decode())
raise httpx.HTTPError(msg) from err
raise requests.HTTPError(msg) from err
return io.BytesIO(response.content)


Expand All @@ -90,9 +90,9 @@ def urlopen(
quote: bool = True,
requests_kwargs: dict | None = None,
) -> BinaryIO:
"""Thin wrapper around httpx get content.
"""Thin wrapper around requests get content.

See httpx.get docs for the `params` and `kwargs` options.
See requests.get docs for the `params` and `kwargs` options.

"""
# This is a horrible hack to work around opendap.co-ops.nos.noaa.gov.
Expand Down Expand Up @@ -123,7 +123,8 @@ def check_url_response(url: str, **kwargs: dict) -> str:
necessary. Otherwise let it fail later and avoid fetching the head.

"""
r = httpx.head(url, **kwargs)
timeout = kwargs.pop("timeout", 10)
r = requests.head(url, timeout=timeout, **kwargs)
r.raise_for_status()
return url

Expand Down Expand Up @@ -159,8 +160,8 @@ def _format_search_string(server: str, query: str) -> str:
def _multi_urlopen(url: str) -> BinaryIO:
"""Simpler url open to work with multiprocessing."""
try:
data = urlopen(url)
except (httpx.HTTPError, httpx.ConnectError):
data = urlopen(url, requests_kwargs={"timeout": 120})
except (requests.HTTPError, requests.ConnectionError):
return None
return data

Expand Down
2 changes: 1 addition & 1 deletion erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ERDDAP:
variables: a list variables to download.
response: default is HTML.
constraints: download constraints, default None (opendap-like url)
params and requests_kwargs: `httpx.get` options
params and requests_kwargs: `requests.get` options

Returns:
-------
Expand Down
6 changes: 3 additions & 3 deletions erddapy/servers/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pathlib import Path
from typing import NamedTuple

import httpx
import pandas as pd
import requests


class Server(NamedTuple):
Expand All @@ -26,9 +26,9 @@ def servers_list() -> dict:
"""
try:
url = "https://raw.githubusercontent.com/IrishMarineInstitute/awesome-erddap/master/erddaps.json"
r = httpx.get(url, timeout=10)
r = requests.get(url, timeout=10)
df_servers = pd.read_json(io.StringIO(r.text))
except httpx.HTTPError:
except requests.HTTPError:
path = Path(__file__).absolute().parent
df_servers = pd.read_json(path.joinpath("erddaps.json"))
# Drop non-public servers.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
httpx>=0.25.0
pandas>=0.25.2,<4
pytz
requests
50 changes: 0 additions & 50 deletions tests/cassettes/test_erddapy/test_erddap2_10.yaml

This file was deleted.

This file was deleted.

Loading