dabla commented on code in PR #56457:
URL: https://github.com/apache/airflow/pull/56457#discussion_r2671845461
##########
providers/edge3/src/airflow/providers/edge3/cli/api_client.py:
##########
@@ -92,39 +92,42 @@ def jwt_generator() -> JWTGenerator:
wait_timeouts=_default_wait,
wait_rate_limited=wait_retry_after(fallback=_default_wait), # No infinite
timeout on HTTP 429
before_sleep=before_sleep_log(logger, logging.WARNING),
+ network_errors=ClientConnectionError,
+ timeouts=ServerTimeoutError,
)
-def _make_generic_request(method: str, rest_path: str, data: str | None =
None) -> Any:
+async def _make_generic_request(method: str, rest_path: str, data: str | None
= None) -> Any:
authorization = jwt_generator().generate({"method": rest_path})
api_url = conf.get("edge", "api_url")
+ content_type = {"Content-Type": "application/json"} if data else {}
headers = {
- "Content-Type": "application/json",
+ **content_type,
"Accept": "application/json",
"Authorization": authorization,
}
api_endpoint = urljoin(api_url, rest_path)
- response = requests.request(method, url=api_endpoint, data=data,
headers=headers)
- response.raise_for_status()
- if response.status_code == HTTPStatus.NO_CONTENT:
- return None
- return json.loads(response.content)
+ async with request(method, url=api_endpoint, data=data, headers=headers)
as response:
+ response.raise_for_status()
+ if response.status == HTTPStatus.NO_CONTENT:
+ return None
+ return json.loads(await response.read())
Review Comment:
I think here you can simply do:
`await response.json()`
The ClientResponse has an async json() method just like it's requests
counterpart
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]