RogerSelwyn / MS365-Calendar

Microsoft 365 Calendar Integration for Home Assistant
MIT License
12 stars 1 forks source link

Internal error 500 #26

Closed SpeijerTom closed 1 month ago

SpeijerTom commented 1 month ago

First, I would like to thank you for your awesome work. (I have been using your O365 integration, but only needed the calendar and because i have multiple tenants, this integration was exactly what I needed).

I have succesfully configured 1 tenant, this works perfectly When adding another tenant/entry (where i followed the same steps), i get no entities back.

If i click on configure, it gives me error 500

Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble

I checked (i believe) all, permissions, retried the client id, secret,

Any idea?

RogerSelwyn commented 1 month ago

Please post your config with relevant details redacted. Also post the full errors displayed in your logs.

SpeijerTom commented 1 month ago

ERROR 1 I see in the debug logging the following : 2024-09-26 10:29:44.904 WARNING (MainThread) [custom_components.ms365_calendar.integration.permissions_integration] 'enable_update' should not be true when 'basic_calendar' is true .for account: BHEALTHY ReadBasic used.

however that error i also get for the other tenant which works perfect

ERROR 2 2024-09-26 10:29:45.879 ERROR (SyncWorker_8) [O365.connection] Client Error: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/me/calendars | Error Message: The mailbox is either inactive, soft-deleted, or is hosted on-premise. | Error Code: 2024-09-26 10:29:45.884 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up ms365_calendar platform for calendar Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/ms365_calendar/calendar.py", line 17, in async_setup_entry return await async_integration_setup_entry(hass, entry, async_add_entities) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 106, in async_integration_setup_entry await async_scan_for_calendars(hass, entry) File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 768, in async_scan_for_calendars calendars = await hass.async_add_executor_job(schedule.list_calendars) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 1933, in list_calendars response = self.con.get(url, params=params or None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 848, in _internal_request raise HTTPError('{} | Error Message: {}'.format(e.args[0], error_message), requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/me/calendars | Error Message: The mailbox is either inactive, soft-deleted, or is hosted on-premise.

however i'm not sure if that is for this integration, or for the previous integration from yourself

ERROR 3

2024-09-26 10:49:24.516 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args (PosixPath('/config/ms365_storage/.MS365-token-cache/ms365_calendar_BHEALTHY.token'), 'r') inside the event loop by custom integration 'ms365_calendar' at custom_components/ms365_calendar/config_flow.py, line 253: return account, account.is_authenticated (offender: /usr/local/lib/python3.12/site-packages/O365/utils/token.py, line 239: with self.token_path.open('r') as token_file:), please create a bug report at https://github.com/RogerSelwyn/MS365-Calendar/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle resp = await handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, request.match_info) File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin return await func(self, request, *args, *kwargs) File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper return await method(view, request, data, args, kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure result = await self._async_configure(flow_id, user_input) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step result: _FlowResultT = await getattr(flow, method)(user_input) File "/config/custom_components/ms365_calendar/config_flow.py", line 105, in async_step_user self._account, is_authenticated = await self._async_try_authentication( File "/config/custom_components/ms365_calendar/config_flow.py", line 253, in _async_try_authentication return account, account.is_authenticated

2024-09-26 10:49:24.517 WARNING (MainThread) [custom_components.ms365_calendar.integration.permissions_integration] 'enable_update' should not be true when 'basic_calendar' is true .for account: BHEALTHY ReadBasic used. 2024-09-26 10:49:24.519 DEBUG (MainThread) [custom_components.ms365_calendar.config_flow] Token file: /config/ms365_storage/.MS365-token-cache/ms365_calendar_BHEALTHY.token

image home-assistant_ms365_calendar_2024-09-26T08-50-01.569Z.log

RogerSelwyn commented 1 month ago
  1. enable_update - just turn off the setting in your config
  2. /config/custom_components/ms365_calendar/integration/calendar_integration.py - this tells you which integration it is, the ms365_calendar integration
  3. Error Message: The mailbox is either inactive, soft-deleted, or is hosted on-premise - This tells you the error coming back from Microsoft (which the integration does not handle because I've never seen it before).
  4. Detected blocking call to open with args (PosixPath('/config/ms365_storage/.MS365-token-cache/ms365_calendar_BHEALTHY.token'), 'r') inside the event loop by custom integration 'ms365_calendar' at custom_components/ms365_calendar/config_flow.py, line 253 - Tells me this is a bug which I need to fix (it is a new check that HA core does, currently a Warning not an error).

I would expect the 500 error is caused by no 3, which you will need to fix. Hopefully the error tells you where your issue is, but it is not something I can advise on or solve. You can validate by testing the relevant call here - https://developer.microsoft.com/en-us/graph/graph-explorer

SpeijerTom commented 1 month ago

Roger,

I found the issue, you may close this issue. Altough I think it is very strange, I created an App registration with an admin user that doesn't have a mailbox assigned... => resulted in that error I now gave a user that has a mailbox, global admin rights, created the app registration

and now it works ...

very strange imo

Stephan-4711 commented 3 weeks ago

did you remove the global admin permission afterwars? This would be a no go here :-(