RobertD502 / home-assistant-petkit

Home Assistant integration for PetKit devices
MIT License
213 stars 32 forks source link

Unknown error occurred #2

Closed DevilsAdjutant closed 1 year ago

DevilsAdjutant commented 1 year ago

After installing this I keep getting the following error

I'm logged out on every mobile device that used the petkit account before,

This error originated from a custom integration.

Logger: aiohttp.server
Source: custom_components/petkit/util.py:28
Integration: PetKit (documentation, issues)
First occurred: 14:04:24 (2 occurrences)
Last logged: 14:07:00

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 145, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 253, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/petkit/config_flow.py", line 90, in async_step_user
    await async_validate_api(self.hass, email, password)
  File "/config/custom_components/petkit/util.py", line 28, in async_validate_api
    devices_query = await client.get_device_roster()
  File "/usr/local/lib/python3.10/site-packages/petkitaio/petkit_client.py", line 143, in get_device_roster
    device_roster = await self._post(url, header, data)
  File "/usr/local/lib/python3.10/site-packages/petkitaio/petkit_client.py", line 345, in _post
    async with self._session.post(url, headers=headers, data=data, timeout=self.timeout) as resp:
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 557, in _request
    resp = await req.send(conn)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 669, in send
    await writer.write_headers(status_line, self.headers)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/http_writer.py", line 130, in write_headers
    buf = _serialize_headers(status_line, headers)
  File "aiohttp/_http_writer.pyx", line 132, in aiohttp._http_writer._serialize_headers
  File "aiohttp/_http_writer.pyx", line 109, in aiohttp._http_writer.to_str
TypeError: Cannot serialize non-str key None
RobertD502 commented 1 year ago

Error resolved:

tz environmental variable is needed for Home Assistant docker installs.

petrutghita commented 1 year ago

Hi Robert. I am still getting this 'Unknown error occured' even after I set the TZ environment variable in Home Assistant Docker. I have never had this issue in the past but it seems it won't go away after this HA update. Can you help please?

RobertD502 commented 1 year ago

Edit: I thought I was responding to the original poster. Unknown error can mean many things. Please post the related log here so I can get more info about what is going on.

Go to Settings --> System --> General and make sure you have a timezone set.

Also, go to your user profile and make sure timezone is set there.

If that doesn't work, please paste the related log here.

petrutghita commented 1 year ago

I tried changing it from HA UI and also from Terminal, but still no success. This is the log:

This error originated from a custom integration.

Logger: aiohttp.server Source: custom_components/petkit/util.py:19 Integration: PetKit (documentation, issues) First occurred: 6:57:13 PM (3 occurrences) Last logged: 6:57:15 PM

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, *request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 181, in post return await super().post(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper result = await method(view, request, data, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 297, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 393, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/petkit/config_flow.py", line 110, in async_step_user await async_validate_api(self.hass, email, password, asia_account) File "/config/custom_components/petkit/util.py", line 19, in async_validate_api client = PetKitClient( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/petkitaio/petkit_client.py", line 75, in init self.tz: str = get_localzone_name() ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/tzlocal/unix.py", line 208, in get_localzone_name _cache_tz_name = _get_localzone_name() ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/tzlocal/unix.py", line 158, in _get_localzone_name raise zoneinfo.ZoneInfoNotFoundError(message) zoneinfo._common.ZoneInfoNotFoundError: 'Multiple conflicting time zone configurations found:\n/etc/timezone: Africa/Lusaka\n/etc/localtime is a symlink to: Europe/Bucharest\nFix the configuration, or set the time zone in a TZ environment variable.\n'

RobertD502 commented 1 year ago

Looks like you have some conflicting timezone issues on the OS that you're running the container on.

1) What did you set the TZ environment variable to for the Home Assistant Docker container?

2) Also, please post the output from running ls -l /etc/localtime in your terminal on the machine that is hosting the docker container (not within the Home Assistant container itself).

3) What OS & version are you running (Ubuntu, Arch, etc)?

petrutghita commented 1 year ago

I set it to Europe/Bucharest when I installed HA. I used this command:

docker run -d \ --name homeassistant \ --privileged \ --restart=unless-stopped \ -e TZ=Europe/Bucharest \ -v /home/petrutghita/Documents:/config \ --network=host \ ghcr.io/home-assistant/home-assistant:stable

This is what ls -l /etc/localtime gets:

pi@raspberrypi:~ $ ls -l /etc/localtime lrwxrwxrwx 1 root root 36 Jul 10 18:54 /etc/localtime -> /usr/share/zoneinfo/Europe/Bucharest

Both Profile and System time zones within HA are set to Europe/Bucharest. I even get the correct time when i run 'date' in docker. I have no idea where /Africa/Lusaka comes from or how I can get rid of it.

Edit: for what is worth I reinstalled HA when I switched apartments and once again after I had some problems with the server. Both times this integration worked flawlessly.

RobertD502 commented 1 year ago

Run sudo timedatectl set-timezone Europe/Bucharest on your raspberry pi.

After that run cat /etc/timezone. It should now output Europe/Bucharest. Restart your Pi after making that change. Let me know if the integration works after doing all of that.

petrutghita commented 1 year ago

I ran those commands and it shows correct timezone Europe/Bucharest, however it still won't let me login and I get the same error.

This error originated from a custom integration.

Logger: aiohttp.server Source: custom_components/petkit/util.py:19 Integration: PetKit (documentation, issues) First occurred: 10:32:17 PM (1 occurrences) Last logged: 10:32:17 PM

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, *request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 181, in post return await super().post(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper result = await method(view, request, data, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 297, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 393, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/petkit/config_flow.py", line 110, in async_step_user await async_validate_api(self.hass, email, password, asia_account) File "/config/custom_components/petkit/util.py", line 19, in async_validate_api client = PetKitClient( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/petkitaio/petkit_client.py", line 75, in init self.tz: str = get_localzone_name() ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/tzlocal/unix.py", line 208, in get_localzone_name _cache_tz_name = _get_localzone_name() ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/tzlocal/unix.py", line 158, in _get_localzone_name raise zoneinfo.ZoneInfoNotFoundError(message) zoneinfo._common.ZoneInfoNotFoundError: 'Multiple conflicting time zone configurations found:\n/etc/timezone: Africa/Lusaka\n/etc/localtime is a symlink to: Europe/Bucharest\nFix the configuration, or set the time zone in a TZ environment variable.\n'

Edit: Isn't there a way to unlink the Africa/Lusaka symlink? I couldn't find any working solution.

RobertD502 commented 1 year ago

In that case it looks to be an issue within the Home Assistant docker container. You'll need to get into the Home Assistant container shell and execute the cat /etc/timezone command.

RobertD502 commented 1 year ago

To get into your container, run the following command docker exec -it homeassistant /bin/bash. Once inside of the container run cd .. to get to the root. After that you can run the cat /etc/timezone command.

petrutghita commented 1 year ago

Ok did that and I got Africa/Lusaka. How do I change it? sudo timedatectl set-timezone Europe/Bucharest doesn't seem to work

RobertD502 commented 1 year ago

You can use an editor to directly edit the /etc/timezone file. I don't believe HA comes with the nano editor, but vi works. So, you'd run sudo vi /etc/timezone. Remove Africa/Lusaka replace it with Europe/Bucharest, save + close the file. Restart the container.

If you haven't used vi before: 1) Once you open the file, type i to insert text. Now you can delete Africa/Lusaka and put Europe/Bucharest. 2) Once you are done editing, press the escape button to exit out of insertion mode. 3) To write the changes and exit vi, press Shift + : (in order to type :) and type wq. The final command should be :wq. Press return to execute the command.

petrutghita commented 1 year ago

Well that solved it. Thank you very much especially for the quick responses. Your integration is flawless and you're awesome to say the least!

RobertD502 commented 1 year ago

Glad I could help! Appreciate the kind words.