-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: 2.9
Are you sure you want to change the base?
Conversation
From the artifact of the previous workflow run
ce45b80
to
b681ff3
Compare
try: | ||
result = json.loads(response.content).get(rasters[layer]["elevation_name"]) | ||
except (TypeError, JSONDecodeError) as exc: | ||
_LOG.warning("Height request to %s failed", request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the exception
_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 |
There was a problem hiding this comment.
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.
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: |
There was a problem hiding this comment.
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}: \ |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
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}: \ |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
_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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with exception
_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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
_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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use URLlib
request = f"{rasters[layer]['url']}/height?easting={lon}&northing={lat}" | |
request = f"{rasters[layer]['url']}/height?{urllib.parse.urlencode({'easting': lon, 'northing': lat})}" |
request = f"{rasters[layers[0]]['url']}/profile.json?geom={geom}\ | ||
&nbPoints={nb_points}&distinct_points=true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use URLlib
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'})}" |
Backport of #11572