Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions findmy/reports/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ async def td_2fa_submit(self, code: str) -> LoginState:
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]:
Expand Down Expand Up @@ -645,12 +645,32 @@ async def fetch_raw_reports(
}

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:
Expand Down