icloud3 icon indicating copy to clipboard operation
icloud3 copied to clipboard

Error handling for connections

Open MrAlucardDante opened this issue 2 years ago • 5 comments

Here are 2 errors that appears multilple times per week (even day sometimes).

They don't seem to be critical, but it might be worth taking a look at it. Maybe dealing with connections in a different manner might solve it, but I'm not a python expert.

Logger: custom_components.icloud3.device_tracker
Source: custom_components/icloud3/pyicloud_ic3.py:119
Integration: icloud3 ([documentation](https://gcobb321.github.io/icloud3/#/), [issues](https://github.com/gcobb321/icloud3/issues))
First occurred: 5 avril 2022, 17:14:40 (90 occurrences)
Last logged: 05:36:10

    ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
    ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1349, in getresponse
    response.begin()
  File "/usr/lib/python3.9/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 285, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1349, in getresponse
    response.begin()
  File "/usr/lib/python3.9/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 285, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/device_tracker.py", line 3155, in _refresh_pyicloud_devices_location_data
    devices_data = self.api.devices.response["content"]
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 664, in devices
    data = FindMyiPhoneServiceManager(service_root, self.session, self.params, self.with_family)
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 753, in __init__
    self.refresh_client(device_id)
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 763, in refresh_client
    req = self.session.post(
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 119, in request
    response = super(PyiCloudSession, self).request(method, url, **kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Logger: custom_components.icloud3.device_tracker
Source: custom_components/icloud3/pyicloud_ic3.py:119
Integration: icloud3 ([documentation](https://gcobb321.github.io/icloud3/#/), [issues](https://github.com/gcobb321/icloud3/issues))
First occurred: 02:00:12 (3 occurrences)
Last logged: 04:12:38
HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Read timed out. (read timeout=None)

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1349, in getresponse
    response.begin()
  File "/usr/lib/python3.9/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 277, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.9/ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 451, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/srv/homeassistant/lib/python3.9/site-packages/urllib3/connectionpool.py", line 357, in _raise_timeout
    raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Read timed out. (read timeout=None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/device_tracker.py", line 3155, in _refresh_pyicloud_devices_location_data
    devices_data = self.api.devices.response["content"]
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 664, in devices
    data = FindMyiPhoneServiceManager(service_root, self.session, self.params, self.with_family)
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 753, in __init__
    self.refresh_client(device_id)
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 763, in refresh_client
    req = self.session.post(
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/icloud3/pyicloud_ic3.py", line 119, in request
    response = super(PyiCloudSession, self).request(method, url, **kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/requests/adapters.py", line 532, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Read timed out. (read timeout=None)

MrAlucardDante avatar Apr 06 '22 18:04 MrAlucardDante

I'm running those versions if it helps : iCloud3 v2.4.7 Home Assistant Core : 2022.3.8, running on python 3.8 HACS : 1.24.3

MrAlucardDante avatar Apr 06 '22 18:04 MrAlucardDante

The connection error indicates iCloud went down or you were routed to a different server which may cause a 2fa request which is not automatically being handled. It can also mean your internet went down or is not responding. There was a change to pyicloud_ic3.py, the iCloud3-iCloud account interface program, to try to catch some of these issues. I haven’t put it in a new release but will add it to the iCloud3 GitHub respository development directory here. Download it to the custom_components/iCloud3 directory and restart HA. I’ll do that tomorrow.

gcobb321 avatar Apr 06 '22 21:04 gcobb321

pyicloud_ic3.py v3.0.0 has been uploaded. See if that fixes your issue

gcobb321 avatar Apr 07 '22 00:04 gcobb321

Sorry for the delay.

I just tried it, and icloud3 can't start with the new file :

iCloud3 Error > An error was encountered setting up the `pyicloud_ic3.py` module. Either the module was not found or there was an error loading it.The iCloud Location Service is disabled and the iOS App tracking_method will be used.

I downloaded the file with curl (and with my browser), I then copied the file in /home/homeassistant/.homeassitant/custom_components/icloud3. pyicloud_ic3

MrAlucardDante avatar May 05 '22 17:05 MrAlucardDante

I have since found that pyicloud3_ic3 v.3.0.0 will not work with iCloud3 v2.4.x and have removed it from the development directory. I have uploaded v2.4.4 version of pyicloud_ic3.py (the version that was released with iCloud3 v2.4.7).

Using pyicloud_ic3.py v3.0.0 is probably leading to the iCloud3 Error

gcobb321 avatar May 05 '22 18:05 gcobb321