mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-25 02:05:54 +02:00
Merge pull request #186 from malmeloo/fix/empty-report-response
fix: workaround empty HTTP response when fetching device locations (#185)
This commit is contained in:
@@ -610,7 +610,7 @@ class AsyncAppleAccount(BaseAppleAccount):
|
|||||||
return await self._login_mobileme()
|
return await self._login_mobileme()
|
||||||
|
|
||||||
@_require_login_state(LoginState.LOGGED_IN)
|
@_require_login_state(LoginState.LOGGED_IN)
|
||||||
async def fetch_raw_reports(
|
async def fetch_raw_reports( # noqa: C901
|
||||||
self,
|
self,
|
||||||
devices: list[tuple[list[str], list[str]]],
|
devices: list[tuple[list[str], list[str]]],
|
||||||
) -> list[LocationReport]:
|
) -> list[LocationReport]:
|
||||||
@@ -645,12 +645,32 @@ class AsyncAppleAccount(BaseAppleAccount):
|
|||||||
}
|
}
|
||||||
|
|
||||||
async def _do_request() -> util.http.HttpResponse:
|
async def _do_request() -> util.http.HttpResponse:
|
||||||
return await self._http.post(
|
# bandaid fix for https://github.com/malmeloo/FindMy.py/issues/185
|
||||||
self._ENDPOINT_REPORTS_FETCH,
|
# Symptom: HTTP 200 but empty response
|
||||||
auth=auth,
|
# Remove when real issue fixed
|
||||||
headers=await self.get_anisette_headers(),
|
retry_counter = 1
|
||||||
json=data,
|
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()
|
r = await _do_request()
|
||||||
if r.status_code == 401:
|
if r.status_code == 401:
|
||||||
|
|||||||
Reference in New Issue
Block a user