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

[Backport 2.9] Get profile and height from service #11575

Open
wants to merge 3 commits into
base: 2.9
Choose a base branch
from

Conversation

c2c-bot-gis-ci-2
Copy link

Backport of #11572

RenataMuellerC2C and others added 2 commits December 10, 2024 07:37
From the artifact of the previous workflow run
try:
result = json.loads(response.content).get(rasters[layer]["elevation_name"])
except (TypeError, JSONDecodeError) as exc:
_LOG.warning("Height request to %s failed", request)
Copy link
Member

Choose a reason for hiding this comment

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

Get the exception

Suggested change
_LOG.warning("Height request to %s failed", request)
_LOG.exception("Height request to %s failed", request)

result = json.loads(response.content).get(rasters[layer]["elevation_name"])
except (TypeError, JSONDecodeError) as exc:
_LOG.warning("Height request to %s failed", request)
raise HTTPInternalServerError(f"Failed to decode JSON response from {request}") from exc
Copy link
Member

Choose a reason for hiding this comment

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

For me, request shouldn't be public.

Suggested change
raise HTTPInternalServerError(f"Failed to decode JSON response from {request}") from exc
raise HTTPInternalServerError(f"Failed to decode JSON response from the internal request") from exc

@@ -181,6 +196,29 @@ def get_index(index_: int) -> tuple[int, int]:

return result

def _get_service_data(
self, layer: str, lat: float, lon: float, rasters: dict[str, Any]
) -> dict[str, Any] | None:
Copy link
Member

Choose a reason for hiding this comment

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

Does it relay return None?
With the new code, it's raise an exception

if not response.ok:
_LOG.warning("Elevation request %s failed with status code %s", request, response.status_code)
raise HTTPInternalServerError(
f"Failed to fetch elevation data from {request}: \
Copy link
Member

Choose a reason for hiding this comment

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

For me, request shouldn't be public.

Suggested change
f"Failed to fetch elevation data from {request}: \
f"Failed to fetch elevation data from internal request: \

points = json.loads(response.content)
except (TypeError, JSONDecodeError) as exc:
_LOG.warning("profile request %s failed", request)
raise HTTPInternalServerError(f"Failed to decode JSON response from {request}") from exc
Copy link
Member

Choose a reason for hiding this comment

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

For me, request shouldn't be public.

Suggested change
raise HTTPInternalServerError(f"Failed to decode JSON response from {request}") from exc
raise HTTPInternalServerError(f"Failed to decode JSON response frominternal request") from exc

if not response.ok:
_LOG.warning("profile request %s failed with status code %s", request, response.status_code)
raise HTTPInternalServerError(
f"Failed to fetch profile data from {request}: \
Copy link
Member

Choose a reason for hiding this comment

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

For me, request shouldn't be public.

Suggested change
f"Failed to fetch profile data from {request}: \
f"Failed to fetch profile data from internal request: \

&nbPoints={nb_points}&distinct_points=true"
response = requests.get(request, timeout=10)
if not response.ok:
_LOG.warning("profile request %s failed with status code %s", request, response.status_code)
Copy link
Member

Choose a reason for hiding this comment

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

error?

Suggested change
_LOG.warning("profile request %s failed with status code %s", request, response.status_code)
_LOG.error("profile request %s failed with status code %s", request, response.status_code)

try:
points = json.loads(response.content)
except (TypeError, JSONDecodeError) as exc:
_LOG.warning("profile request %s failed", request)
Copy link
Member

Choose a reason for hiding this comment

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

with exception

Suggested change
_LOG.warning("profile request %s failed", request)
_LOG.exception("profile request %s failed", request)

_LOG.info("Doing height request to %s", request)
response = requests.get(request, timeout=10)
if not response.ok:
_LOG.warning("Elevation request %s failed with status code %s", request, response.status_code)
Copy link
Member

Choose a reason for hiding this comment

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

error?

Suggested change
_LOG.warning("Elevation request %s failed with status code %s", request, response.status_code)
_LOG.error("Elevation request %s failed with status code %s", request, response.status_code)

def _get_service_data(
self, layer: str, lat: float, lon: float, rasters: dict[str, Any]
) -> dict[str, Any] | None:
request = f"{rasters[layer]['url']}/height?easting={lon}&northing={lat}"
Copy link
Member

Choose a reason for hiding this comment

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

Use URLlib

Suggested change
request = f"{rasters[layer]['url']}/height?easting={lon}&northing={lat}"
request = f"{rasters[layer]['url']}/height?{urllib.parse.urlencode({'easting': lon, 'northing': lat})}"

Comment on lines +74 to +75
request = f"{rasters[layers[0]]['url']}/profile.json?geom={geom}\
&nbPoints={nb_points}&distinct_points=true"
Copy link
Member

Choose a reason for hiding this comment

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

Use URLlib

Suggested change
request = f"{rasters[layers[0]]['url']}/profile.json?geom={geom}\
&nbPoints={nb_points}&distinct_points=true"
request = f"{rasters[layers[0]]['url']}/profile.json?{urllib.parse.urlencode({'geom': geom, 'nbPoints': nb_points, 'distinct_points': 'true'})}"

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

Successfully merging this pull request may close these issues.

3 participants