From 26ce20489b7567f1cdda151835d58ca01d6e6d52 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Fri, 17 Nov 2023 16:45:38 -0300 Subject: [PATCH] don't use env vars --- erddapy/core/url.py | 19 +++++++++++-------- erddapy/erddapy.py | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/erddapy/core/url.py b/erddapy/core/url.py index 6279adf..f8928b3 100644 --- a/erddapy/core/url.py +++ b/erddapy/core/url.py @@ -43,18 +43,21 @@ def _sort_url(url): def _urlopen(url: str, auth: tuple | None = None, **kwargs: dict) -> BinaryIO: if "timeout" not in kwargs.keys(): kwargs["timeout"] = 60 + 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] - login_page = f"{p.scheme}://{p.netloc}{base}/login.html" - client.post( - login_page, - data={ - "user": os.getenv("ERDDAP_USERNAME"), - "password": os.getenv("ERDDAP_PASSWORD"), - }, - ) + 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: diff --git a/erddapy/erddapy.py b/erddapy/erddapy.py index 6e05c4a..e056e9a 100644 --- a/erddapy/erddapy.py +++ b/erddapy/erddapy.py @@ -362,6 +362,7 @@ 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, pandas_kwargs=dict(**kw)) def to_ncCF(self, protocol: str = None, **kw):