Open-EO / openeo-python-client

Python client API for OpenEO
https://open-eo.github.io/openeo-python-client/
Apache License 2.0
143 stars 36 forks source link

load_stac() -> metadata_from_stac() Long error #554

Closed EmileSonneveld closed 2 months ago

EmileSonneveld commented 3 months ago

I got this long error message when doing a load_stac:

Failed to extract cube metadata from STAC URL /data/users/Public/victor.verhaert/ANINStac/ERA5-TOTAL-PRECIPITATION/v0.1/collection.json
Traceback (most recent call last):
  File "/home/emile/openeo/openeo-python-client/openeo/rest/connection.py", line 1372, in load_stac
    cube.metadata = metadata_from_stac(url)
  File "/home/emile/openeo/openeo-python-client/openeo/metadata.py", line 548, in metadata_from_stac
    stac_object = pystac.read_file(href=url)
  File "/home/emile/openeo/venv/lib/python3.8/site-packages/pystac/__init__.py", line 161, in read_file
    return stac_io.read_stac_object(href)
  File "/home/emile/openeo/venv/lib/python3.8/site-packages/pystac/stac_io.py", line 234, in read_stac_object
    d = self.read_json(source, *args, **kwargs)
  File "/home/emile/openeo/venv/lib/python3.8/site-packages/pystac/stac_io.py", line 205, in read_json
    txt = self.read_text(source, *args, **kwargs)
  File "/home/emile/openeo/venv/lib/python3.8/site-packages/pystac/stac_io.py", line 282, in read_text
    return self.read_text_from_href(href)
  File "/home/emile/openeo/venv/lib/python3.8/site-packages/pystac/stac_io.py", line 305, in read_text_from_href
    with open(href, encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/data/users/Public/victor.verhaert/ANINStac/ERA5-TOTAL-PRECIPITATION/v0.1/collection.json'

It is not a bug, but a but is distracting, as the file does exist on the backend

Command used:

load_collection = connection.load_stac(
    url="/data/users/Public/victor.verhaert/ANINStac/ERA5-TOTAL-PRECIPITATION/v0.1/collection.json",
    temporal_extent=temporal_extent,
    spatial_extent=spatial_extent,
    bands=["total_precipitation"],
)
bossie commented 3 months ago

I'm not sure we want to hide this, it is a useful warning.

Also note that load_stac is only supposed to work with HTTP(S) URLs and it is just convenient that it also accepts paths on disk: https://openeo.org/documentation/1.0/processes.html#load_stac

soxofaan commented 3 months ago

Also note that this is (currently) just a warning, not a breaking error because of the try-except https://github.com/Open-EO/openeo-python-client/blob/59655b8c16f468c751c4381a29e99674f58be344/openeo/rest/connection.py#L1371-L1374

Maybe we should not not show the stack trace to make it look less panicky

JeroenVerstraelen commented 2 months ago

Not likely that a regular user will see this. Requires a local mount.

load_stac is only supported for https urls, this warning is to be expected. Typo in url should show this warning, so best not to hide it.