diff --git a/erddapy/core/url.py b/erddapy/core/url.py
index 351b37e..211f560 100644
--- a/erddapy/core/url.py
+++ b/erddapy/core/url.py
@@ -61,12 +61,23 @@ 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(
- quote_url(url),
- follow_redirects=True,
- auth=auth,
- **kwargs,
- )
+ user = kwargs.pop("user", None)
+ password = kwargs.pop("password", None)
+ with httpx.Client() as client:
+ p = parse.urlparse(url)
+ protocol = "tabledap" if "tabledap" in p.path else "griddap"
+ base = p.path.split(f"/{protocol}/")[0]
+ if user is not None and password is not None:
+ login_page = f"{p.scheme}://{p.netloc}{base}/login.html"
+ client.post(
+ login_page,
+ data={
+ "user": f"{user}",
+ "password": f"{password}",
+ },
+ )
+ response = client.get(url, follow_redirects=True, auth=auth, **kwargs)
+
try:
response.raise_for_status()
except httpx.HTTPError as err:
diff --git a/erddapy/erddapy.py b/erddapy/erddapy.py
index ac8c4f6..d4b233c 100644
--- a/erddapy/erddapy.py
+++ b/erddapy/erddapy.py
@@ -417,6 +417,9 @@ def to_pandas(
response = kw.pop("response", "csvp")
distinct = kw.pop("distinct", False)
url = self.get_download_url(response=response, distinct=distinct)
+ requests_kwargs = (
+ requests_kwargs if requests_kwargs else self.requests_kwargs
+ )
return to_pandas(
url,
requests_kwargs=requests_kwargs,
diff --git a/tests/cassettes/test_urlopen_raise.yaml b/tests/cassettes/test_urlopen_raise.yaml
deleted file mode 100644
index 64917aa..0000000
--- a/tests/cassettes/test_urlopen_raise.yaml
+++ /dev/null
@@ -1,318 +0,0 @@
-interactions:
-- request:
- body: ''
- headers:
- accept:
- - '*/*'
- accept-encoding:
- - gzip, deflate, br
- connection:
- - keep-alive
- host:
- - developer.mozilla.org
- user-agent:
- - python-httpx/0.23.0
- method: GET
- uri: https://developer.mozilla.org/en-US/404
- response:
- content: "
\U0001F937\U0001F3FD\u200D\u2640\uFE0F
- Page not found | null"
- headers:
- Cache-Control:
- - no-store, must-revalidate
- Connection:
- - keep-alive
- Content-Encoding:
- - br
- Content-Security-Policy:
- - default-src 'self'; script-src 'report-sample' 'self' www.google-analytics.com/analytics.js
- 'sha256-JEt9Nmc3BP88wxuTZm9aKNu87vEgGmKW1zzy/vb1KPs=' polyfill.io/v3/polyfill.min.js
- assets.codepen.io production-assets.codepen.io 'sha256-x6Tv+AdV5e6dcolO0TEo+3BG4H2nG2ACjyG8mz6QCes='
- 'sha256-GA8+DpFnqAM/vwERTpb5zyLUaN5KnOhctfTsqWfhaUA='; script-src-elem 'report-sample'
- 'self' www.google-analytics.com/analytics.js 'sha256-JEt9Nmc3BP88wxuTZm9aKNu87vEgGmKW1zzy/vb1KPs='
- polyfill.io/v3/polyfill.min.js assets.codepen.io production-assets.codepen.io
- 'sha256-x6Tv+AdV5e6dcolO0TEo+3BG4H2nG2ACjyG8mz6QCes=' 'sha256-GA8+DpFnqAM/vwERTpb5zyLUaN5KnOhctfTsqWfhaUA=';
- style-src 'report-sample' 'self' 'unsafe-inline'; object-src 'none'; base-uri
- 'self'; connect-src 'self' updates.developer.allizom.org updates.developer.mozilla.org
- www.google-analytics.com stats.g.doubleclick.net; font-src 'self'; frame-src
- 'self' interactive-examples.mdn.mozilla.net interactive-examples.prod.mdn.mozilla.net
- interactive-examples.stage.mdn.mozilla.net mdn.github.io yari-demos.prod.mdn.mozit.cloud
- mdn.mozillademos.org yari-demos.stage.mdn.mozit.cloud jsfiddle.net www.youtube-nocookie.com
- codepen.io www.surveygizmo.com; img-src 'self' *.githubusercontent.com *.googleusercontent.com
- *.gravatar.com mozillausercontent.com firefoxusercontent.com profile.stage.mozaws.net
- profile.accounts.firefox.com mdn.mozillademos.org media.prod.mdn.mozit.cloud
- media.stage.mdn.mozit.cloud interactive-examples.mdn.mozilla.net interactive-examples.prod.mdn.mozilla.net
- interactive-examples.stage.mdn.mozilla.net wikipedia.org www.google-analytics.com
- www.gstatic.com; manifest-src 'self'; media-src 'self' archive.org videos.cdn.mozilla.net;
- child-src 'self'; worker-src 'self';
- Content-Type:
- - text/html; charset=utf-8
- Date:
- - Wed, 27 Jul 2022 14:57:55 GMT
- ETag:
- - W/"eb71930fca1bf0f5a1c58df01562ab83"
- Last-Modified:
- - Wed, 27 Jul 2022 00:41:56 GMT
- Server:
- - AmazonS3
- Strict-Transport-Security:
- - max-age=63072000
- Transfer-Encoding:
- - chunked
- Vary:
- - Accept-Encoding
- Via:
- - 1.1 c59efe844fd614ff20a756172908fed0.cloudfront.net (CloudFront)
- X-Amz-Cf-Id:
- - OI75oo7LYqVH6UtsN-ZM_Npub4Dwab18TTS_VaLnbdwgwRjCJaY0uA==
- X-Amz-Cf-Pop:
- - GRU1-C1
- X-Cache:
- - Error from cloudfront
- X-Content-Type-Options:
- - nosniff
- X-Frame-Options:
- - DENY
- X-XSS-Protection:
- - 1; mode=block
- http_version: HTTP/1.1
- status_code: 404
-version: 1