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 Feb 27, 2024
1 parent 4d9d711 commit 26ce204
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 26ce204

Please sign in to comment.