Skip to content

Commit

Permalink
don't use env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Jan 17, 2024
1 parent 3ee6d2d commit 0de7920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import copy
import functools
import io
import os
from datetime import datetime
from typing import BinaryIO, Dict, List, Optional, Tuple, Union
from urllib.parse import quote_plus, urlparse
Expand All @@ -20,18 +19,21 @@
def _urlopen(url: str, auth: Optional[tuple] = 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 = 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:
Expand Down
1 change: 1 addition & 0 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,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):
Expand Down

0 comments on commit 0de7920

Please sign in to comment.