Open mattijn opened 1 month ago
Not sure if this actually does the trick. See the log https://github.com/geopandas/geopandas/actions/runs/9323915991/job/25668099398#step:5:5174
Uses a partial data access if Accept-Ranges is supported (currently only for
fiona
)
As I mentioned on the issue (https://github.com/geopandas/geopandas/issues/3284#issuecomment-2131268003), my understanding is that this should just as much work for pyogrio as it does for fiona (or, to phrase it differently, I don't understand why there would be a difference, since it is GDAL that is eventually failing)
Fix #3284.
This pull request addresses the problem where redirects from jsdelivr lack necessary headers, causing unexpected failures. The issue is hard to reproduce.
Ideally, jsdelivr provides the needed headers upon redirecting, but this PR also improves the code by separating the handling of
fiona
andpyogrio
as backends, so it might still be useful.Next to formatting, this PR introduces a new function named
_url_supports_random_access()
. It checks if the Accept-Ranges header is"bytes"
. Tries aHEAD
request first, falls back to aGET
request if necessary (eg. some endpoints have noHEAD
method enabled). Uses a partial data access if Accept-Ranges is supported (currently only forfiona
) and retrieves the entire file usingurllib
if Accept-Ranges is not supported or if partial data access through fiona somehow still fails (as is the case in #3284).Btw, I think GDAL fails due to the missing Content-Length element in the header and not on a missing Accept-Ranges in the header.
But as far I have observed, if there is no Accept-Ranges defined then there is no Content-Length defined.