FindMy.py icon indicating copy to clipboard operation
FindMy.py copied to clipboard

throws meaningful exception for auth failure

Open ubertao opened this issue 3 months ago • 4 comments

I'm getting the following error for calling AppleAccount.fetch_reports():

Traceback (most recent call last):
  File "/opt/./update_findmy_locations.py", line 137, in <module>
    main()
  File "/opt/./update_findmy_locations.py", line 129, in main
    reports = fetch_reports_from_apple(acc, device, fetch_from, fetch_to)
  File "/opt/./update_findmy_locations.py", line 88, in fetch_reports_from_apple
    reports = acc.fetch_reports(list(lookup_keys), fetch_from, fetch_to)
  File "/usr/local/lib/python3.10/site-packages/findmy/reports/account.py", line 1045, in fetch_reports
    return self._evt_loop.run_until_complete(coro)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.10/site-packages/findmy/reports/account.py", line 641, in fetch_reports
    return await self._reports.fetch_reports(
  File "/usr/local/lib/python3.10/site-packages/findmy/reports/reports.py", line 239, in fetch_reports
    reports.extend(await self._fetch_reports(date_from, date_to, chunk))
  File "/usr/local/lib/python3.10/site-packages/findmy/reports/reports.py", line 260, in _fetch_reports
    data = await self._account.fetch_raw_reports(start_date, end_date, ids)
  File "/usr/local/lib/python3.10/site-packages/findmy/reports/account.py", line 596, in fetch_raw_reports
    resp = r.json()
  File "/usr/local/lib/python3.10/site-packages/findmy/util/http.py", line 48, in json
    return json.loads(self.text())
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7ffffb9c7790>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7ffffb93e440>, 1058485.242966568)]']
connector: <aiohttp.connector.TCPConnector object at 0x7ffffb9c7760>
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7ffffb9c7910>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7ffffb9c9f00>, 1058486.638551861)]']
connector: <aiohttp.connector.TCPConnector object at 0x7ffffb9c78b0>

The real issue is a 401 error with an empty response from iCloud API. May we have a meaningful exception so my code knows how to handle the re-login?

ubertao avatar May 16 '24 10:05 ubertao