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

Do something when STAC endpoint url ends with "/" #369

Closed
remicres opened this issue Dec 3, 2022 · 7 comments · Fixed by #373
Closed

Do something when STAC endpoint url ends with "/" #369

remicres opened this issue Dec 3, 2022 · 7 comments · Fixed by #373

Comments

@remicres
Copy link

remicres commented Dec 3, 2022

Hi,

When the STAC enpoint ends with "/", random things crashes in pystac.

from pystac_client import Client
api1 = Client("https://some-stac-api.org/")  # erratically works
api2 = Client("https://some-stac-api.org")  # works 

Maybe it could be more user/developer friendly to throw an exception when the enpoint is badly formed (I spent like 30 minutes figuring out why, I guess its a classic for newcomers).
Or, fix the url, or use urllib or something else to concatenate URL?

@gadomski
Copy link
Member

gadomski commented Dec 6, 2022

Can you provide examples of the breakages? I just tried a couple of queries using with and without a trailing / and they seemed to work fine.

@remicres
Copy link
Author

remicres commented Dec 6, 2022

Yes it looks like it depends on the API. Our own API is still internal right now (we have used STAC-FastAPI out of the box) but here is another one on which I can reproduce the issue: https://data.geo.admin.ch/api/stac/v0.9

@gadomski
Copy link
Member

gadomski commented Dec 6, 2022

That endpoint is pretty old -- it's stac_version is v0.9.0 and it doesn't have any listed conformance classes. Do you have a server example that's in the STAC-API v1.0.0-rc.* range?

@remicres
Copy link
Author

remicres commented Dec 7, 2022

Yes I have one, but not public. It consists of pgstac + stac-fastapi (built two weeks ago from the stac-fastapi repository, master branch) so I believe it is in the v1.0.0-rc.* range... how can I check that?
It's running in k8s behind an ingress that does basic url rewrite, I don't think that is the cause (the pystac Client just append api to the endpoint right?)
Thanks

@gadomski
Copy link
Member

gadomski commented Dec 7, 2022

I tested against the planetary computer (https://planetarycomputer.microsoft.com/api/stac/v1), which is also pgstac + stac-fastapi, and haven't had any issues as of yet. Can you try some of your problematic queries against that endpoint, and post any results here?

@remicres
Copy link
Author

remicres commented Dec 7, 2022

Sure. Here is what I got from scratch.

Run docker image (fresh build from master branch of stac-utils/stacapi)

cresson@cin-mo-gpu:~/integration-tests$ docker run -e ... -ti -p 8000:8082 stac-fastapi:main

Run python code from another server:

from pystac_client import Client
url = ...
api = Client.open(url)
print([c for c in api.get_collections()])

With url = "http://10.134.xxx.yyy:8000"

Client:

[]

STAC FastAPI server logs:

INFO:     Will watch for changes in these directories: ['/stac-fastapi']
INFO:     Uvicorn running on http://0.0.0.0:8082 (Press CTRL+C to quit)
INFO:     Started reloader process [1] using StatReload
INFO:     Started server process [8]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     10.34.xxx.zzz:53328 - "GET / HTTP/1.1" 200 OK
INFO:     10.34.xxx.zzz:53328 - "GET /collections HTTP/1.1" 200 OK

With url = "http://10.134.xxx.yyy:8000/" (with a "/" at the end)

Output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <listcomp>
  File "/usr/local/lib/python3.8/dist-packages/pystac_client/client.py", line 258, in get_collections
    for page in self._stac_io.get_pages(url):  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/pystac_client/stac_api_io.py", line 220, in get_pages
    page = self.read_json(url, method=method, parameters=parameters)
  File "/usr/local/lib/python3.8/dist-packages/pystac/stac_io.py", line 198, in read_json
    txt = self.read_text(source, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pystac_client/stac_api_io.py", line 97, in read_text
    return self.request(href, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pystac_client/stac_api_io.py", line 144, in request
    raise APIError.from_response(resp)
pystac_client.exceptions.APIError: {"detail":"Not Found"}

STAC FastAPI server logs:

...
INFO:     10.34.xxx.zzz:53332 - "GET / HTTP/1.1" 200 OK
INFO:     10.34.xxx.zzz:53332 - "GET //collections HTTP/1.1" 404 Not Found

@gadomski
Copy link
Member

gadomski commented Dec 7, 2022

Thanks for the example! I'm now able to reproduce. Fix in #373.

My tests weren't failing because https://planetarycomputer.microsoft.com/api/stac/v1/collections and https://planetarycomputer.microsoft.com/api/stac/v1//collections (notice the double slash) both work. But using a vanilla stac-fastapi I was able to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants