From c062723673222cdbf453508bda9f9860d995100b Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Mon, 29 Sep 2025 22:59:58 +0200 Subject: [PATCH] fix: workaround empty HTTP response when fetching device locations (#185) --- findmy/reports/account.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/findmy/reports/account.py b/findmy/reports/account.py index b751d62..7cbd571 100644 --- a/findmy/reports/account.py +++ b/findmy/reports/account.py @@ -610,7 +610,7 @@ class AsyncAppleAccount(BaseAppleAccount): return await self._login_mobileme() @_require_login_state(LoginState.LOGGED_IN) - async def fetch_raw_reports( + async def fetch_raw_reports( # noqa: C901 self, devices: list[tuple[list[str], list[str]]], ) -> list[LocationReport]: @@ -645,12 +645,32 @@ class AsyncAppleAccount(BaseAppleAccount): } async def _do_request() -> util.http.HttpResponse: - return await self._http.post( - self._ENDPOINT_REPORTS_FETCH, - auth=auth, - headers=await self.get_anisette_headers(), - json=data, - ) + # bandaid fix for https://github.com/malmeloo/FindMy.py/issues/185 + # Symptom: HTTP 200 but empty response + # Remove when real issue fixed + retry_counter = 1 + while True: + resp = await self._http.post( + self._ENDPOINT_REPORTS_FETCH, + auth=auth, + headers=await self.get_anisette_headers(), + json=data, + ) + + if resp.status_code != 200 or resp.text().strip(): + return resp + + logger.warning( + "Empty response received when fetching reports, retrying (%d/3)", + retry_counter, + ) + retry_counter += 1 + + if retry_counter > 3: + logger.warning("Max retries reached, returning empty response") + return resp + + await asyncio.sleep(2) r = await _do_request() if r.status_code == 401: