RogerSelwyn / O365-HomeAssistant

Office 365 integration for Home Assistant
MIT License
203 stars 15 forks source link

Update Calendar Fails errors in logs #242

Closed smarthomefamilyverrips closed 2 months ago

smarthomefamilyverrips commented 4 months ago

I keep getting calendar update failing errors in logs and also noticed that my calendar entity created by the integration not changes to state "on" during calendar events. I already did try to delete my token and reauthenticate the integration but it not helped.

This is in my logs:

Logger: homeassistant.helpers.entity Source: helpers/entity.py:941 First occurred: 18:52:43 (4 occurrences) Last logged: 22:46:44

Update for calendar.cam4_agenda_cam4 fails Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 462, in _make_request httplib_response = conn.getresponse() ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 1423, in getresponse response.begin() File "/usr/local/lib/python3.12/http/client.py", line 331, in begin version, status, reason = self._read_status() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 300, 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 "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 667, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 801, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 552, in increment raise six.reraise(type(error), error, _stacktrace) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/packages/six.py", line 769, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 462, in _make_request httplib_response = conn.getresponse() ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 1423, in getresponse response.begin() File "/usr/local/lib/python3.12/http/client.py", line 331, in begin version, status, reason = self._read_status() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 300, 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 "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 941, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1289, in async_device_update await self.async_update() File "/config/custom_components/o365/calendar.py", line 297, in async_update await self.data.async_update(self.hass) File "/config/custom_components/o365/calendar.py", line 667, in async_update results = await self.async_o365_get_events( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/o365/calendar.py", line 560, in async_o365_get_events events = await self._async_calendar_schedule_get_events( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/o365/calendar.py", line 625, in _async_calendar_schedule_get_events return await hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/calendar.py", line 1797, in get_events response = self.con.get(url, params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 898, in get return self.oauth_request(url, 'get', params=params, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 887, in oauth_request return self._internal_request(self.session, url, method, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 802, in _internal_request if self.refresh_token() is False: ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 699, in refresh_token self.session.refresh_token( File "/usr/local/lib/python3.12/site-packages/requests_oauthlib/oauth2_session.py", line 476, in refresh_token r = self.post( ^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 637, in post return self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests_oauthlib/oauth2_session.py", line 566, in request return super(OAuth2Session, self).request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 682, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

RogerSelwyn commented 4 months ago

My guess is there is an unstable connection to the Microsoft service, this shows a failure in connectivity and unfortunately as far as I can see not a code issue.

You can try recreating the app secret, then delete your token and reauthenticate.

smarthomefamilyverrips commented 4 months ago

My guess is there is an unstable connection to the Microsoft service, this shows a failure in connectivity and unfortunately as far as I can see not a code issue.

You can try recreating the app secret, then delete your token and reauthenticate.

@RogerSelwyn will this also cause the calendar.entity to not turn from "off" to "on" state during a calendar event?

RogerSelwyn commented 4 months ago

If it can't contact MS365 the entity won't update and therefore the state won't change.

Does it ever update?

smarthomefamilyverrips commented 4 months ago

If it can't contact MS365 the entity won't update and therefore the state won't change.

Does it ever update?

Today it didn't turn on nor off, yesterday did turn on at one event but not off and did turn on and off at second event, Monday did turn on and off as expected.... so yesterday had a hick up, and today not changed state at all.

I will tomorrow try setup and installing the new MS365 Calendar integration you created as that is all I use/need anyway from this 0365 integration and will see how that goes :)

smarthomefamilyverrips commented 3 months ago

@RogerSelwyn I did install the MS365 Calendar integration and unfortunately it gives me same error.

This error originated from a custom integration.

Logger: homeassistant Source: custom_components/ms365_calendar/integration/calendar_integration.py:597 integration: Micosoft 365 - Calendar (documentation, issues) First occurred: 22:39:02 (1 occurrences) Last logged: 22:39:02

Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 462, in _make_request httplib_response = conn.getresponse() ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 1423, in getresponse response.begin() File "/usr/local/lib/python3.12/http/client.py", line 331, in begin version, status, reason = self._read_status() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 300, 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 "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 667, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 801, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 552, in increment raise six.reraise(type(error), error, _stacktrace) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/packages/six.py", line 769, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 462, in _make_request httplib_response = conn.getresponse() ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 1423, in getresponse response.begin() File "/usr/local/lib/python3.12/http/client.py", line 331, in begin version, status, reason = self._read_status() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/http/client.py", line 300, 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 "/usr/src/homeassistant/homeassistant/components/calendar/trigger.py", line 255, in _handle_refresh self._events.extend(await self._fetcher(self._timespan)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/calendar/trigger.py", line 133, in async_get_events active_events = await fetcher(offset_timespan) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/calendar/trigger.py", line 115, in async_get_events return await entity.async_get_events(hass, timespan.start, end_time) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 263, in async_get_events return await self.data.async_get_events(hass, start_date, end_date) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 611, in async_get_events results = await self.async_ms365_get_events(hass, start_date, end_date) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 532, in async_ms365_get_events events = await self._async_calendar_schedule_get_events( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 597, in _async_calendar_schedule_get_events return await hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/calendar.py", line 1797, in get_events response = self.con.get(url, params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 898, in get return self.oauth_request(url, 'get', params=params, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 887, in oauth_request return self._internal_request(self.session, url, method, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 802, in _internal_request if self.refresh_token() is False: ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/O365/connection.py", line 699, in refresh_token self.session.refresh_token( File "/usr/local/lib/python3.12/site-packages/requests_oauthlib/oauth2_session.py", line 476, in refresh_token r = self.post( ^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 637, in post return self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests_oauthlib/oauth2_session.py", line 566, in request return super(OAuth2Session, self).request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 682, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

RogerSelwyn commented 3 months ago

It really looks like you have an unstable route to the MS365 service. If it works sometimes or even just loads the calendar once (it is doing the same call every time) then there is a problem with your connection. Not quite true because when you go to the calendar pane it places a very similar but different call, you can see the different routes in the errors you posted. You can enable debug logging for the underlying Python module, but you will get a lot of logs which will likely tell you the same thing. If you want to do that let me know and I’ll let you know what to add.

smarthomefamilyverrips commented 3 months ago

It really looks like you have an unstable route to the MS365 service. If it works sometimes or even just loads the calendar once (it is doing the same call every time) then there is a problem with your connection. Not quite true because when you go to the calendar pane it places a very similar but different call, you can see the different routes in the errors you posted. You can enable debug logging for the underlying Python module, but you will get a lot of logs which will likely tell you the same thing. If you want to do that let me know and I’ll let you know what to add.

@RogerSelwyn thanks for your response, what could cause the unstable route? Or any idea why this started to happen after the latest update, I not had this on previous version v4.8.0

RogerSelwyn commented 3 months ago

You didn’t say before that you had updated. What did you update and did you try downgrading again?

EDIT: just saw you said 4.8.0. Did you try downgrading?

smarthomefamilyverrips commented 3 months ago

You didn’t say before that you had updated. What did you update and did you try downgrading again?

EDIT: just saw you said 4.8.0. Did you try downgrading?

No I did not try downgrading, I got a lot of errors when I did install the integration and you helped me then so I could use exclusion from logs #231

After your beta fixes it was all OK also on v4.8.0 but started after I updated to latest version to my knowledge

RogerSelwyn commented 3 months ago

To answer why 4.8.0 might do this, I can’t see anything in the release notes that might cause an issue. I would recommend going back to previous version, if that fixes your problem then I would suggest adding the python-o365 debug logging.

smarthomefamilyverrips commented 3 months ago

To answer why 4.8.0 might do this, I can’t see anything in the release notes that might cause an issue. I would recommend going back to previous version, if that fixes your problem then I would suggest adding the python-o365 debug logging.

@RogerSelwyn I can just install version 4.8.0 using HACS to roll back?

RogerSelwyn commented 3 months ago

Updated to which latest version? Try downgrading, it is the normal thing to try to diagnose whether the upgrade caused the issue.

smarthomefamilyverrips commented 3 months ago

I did go from v4.8.0 that was working to v4.8.2

RogerSelwyn commented 3 months ago

To answer why 4.8.0 might do this, I can’t see anything in the release notes that might cause an issue. I would recommend going back to previous version, if that fixes your problem then I would suggest adding the python-o365 debug logging.

@RogerSelwyn I can just install version 4.8.0 using HACS to roll back?

Yes. Redownload lets you pick a version

smarthomefamilyverrips commented 3 months ago

To answer why 4.8.0 might do this, I can’t see anything in the release notes that might cause an issue. I would recommend going back to previous version, if that fixes your problem then I would suggest adding the python-o365 debug logging.

@RogerSelwyn I can just install version 4.8.0 using HACS to roll back?

Yes. Redownload lets you pick a version

Thank you, I will try this and keep you posted

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

smarthomefamilyverrips commented 2 months ago

@RogerSelwyn rollback to 4.8.0 did fix this for me, but I now did go to the M365 Calendar integration and stopped using the O365 integration. Sorry I did forget to update this issue.

smarthomefamilyverrips commented 2 months ago

I will close the issue now as it is solved for me