Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pass/login functionality #331

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
files: requirements-dev.txt

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.7.0
hooks:
- id: mypy
exclude: docs/source/conf.py
Expand Down
18 changes: 17 additions & 1 deletion erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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(url, follow_redirects=True, auth=auth, **kwargs)
user = kwargs.pop("user", None)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abkfenris I have no idea how/where to test this. I never encountered a password protected ERDDAP server. Do you have any tips for me here to move this PR forward?

PS: Everything may change soon if we get a GSoC candidate to work on ioos/gsoc#44

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I haven't played with a passworded ERDDAP either, and it's been long enough that the research that I've done has been garbage collected.

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:
Expand Down
3 changes: 3 additions & 0 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,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,
Expand Down
Loading
Loading