hydroshare / hsclient

A python client for interacting with HydroShare in an object oriented way.
https://hydroshare.github.io/hsclient/
BSD 3-Clause "New" or "Revised" License
1 stars 4 forks source link

Using hsclient.HydroShare requires user have account #26

Open aaraney opened 2 years ago

aaraney commented 2 years ago

A user must have a HydroShare account and login to use hsclient.HydroShare, as a user I would like the choice to browse anonymously. I am not sure the implications this has on using https://hydroshare.org/hsapi, however public resources are still discoverable and queryable via the browser without logging in. This may be an edge case that is undesirable, but I think it is worth documenting in an issue.

I believe this stems from HydroShareSession's login logic. Currently, the requests session object is given username=None, password=None by default.

from hsclient import HydroShare

session = HydroShare()
res = session.resource("51188b5303514b20b1b092a24c6620e9")

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 910, in resource
    res.metadata
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 188, in metadata
    return self._metadata
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 95, in _metadata
    self._retrieved_metadata = self._retrieve_and_parse(self.metadata_path)
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 193, in metadata_path
    return urlparse(str(self._map.describes.is_documented_by)).path
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 89, in _map
    self._retrieved_map = self._retrieve_and_parse(self._map_path)
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 151, in _retrieve_and_parse
    file_str = self._hs_session.retrieve_string(path)
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 673, in retrieve_string
    file = self.get(path, status_code=200, allow_redirects=True)
  File "~/github/hydroshare_jupyter_sync/venv/lib/python3.8/site-packages/hsclient/hydroshare.py", line 737, in get
    raise Exception(
Exception: Failed GET https://www.hydroshare.org:443/resource/51188b5303514b20b1b092a24c6620e9/data/resourcemap.xml/, status_code 401, message b'{"detail":"Invalid username/password."}'
huard commented 1 year ago

This would be useful for our test suite and documentation where we don't want to expose auth information.