Logger: aiohttp.server
Source: custom_components/yi_hack/views.py:105
Integration: Yi Cam con yi-hack (documentation, issues)
First occurred: 10:13:43 (64 occurrences)
Last logged: 10:22:31
Error handling request
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
resp = await request_handler(request)
File "/usr/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
File "/usr/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
File "/usr/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
return await handler(request)
File "/usr/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 222, in forwarded_middleware
return await handler(request)
File "/usr/lib/python3.10/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
return await handler(request)
File "/usr/lib/python3.10/site-packages/homeassistant/components/http/ban.py", line 82, in ban_middleware
return await handler(request)
File "/usr/lib/python3.10/site-packages/homeassistant/components/http/auth.py", line 236, in auth_middleware
return await handler(request)
File "/usr/lib/python3.10/site-packages/homeassistant/components/http/view.py", line 136, in handle
result = await result
File "/config/custom_components/yi_hack/views.py", line 72, in get
return await self._handle_request(request, **kwargs)
File "/config/custom_components/yi_hack/views.py", line 105, in _handle_request
async with self._websession.request(
File "/usr/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__
self._resp = await self._coro
File "/usr/lib/python3.10/site-packages/aiohttp/client.py", line 557, in _request
resp = await req.send(conn)
File "/usr/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 669, in send
await writer.write_headers(status_line, self.headers)
File "/usr/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 <requests.auth.HTTPBasicAuth object at 0x71ad4dd60bb0>
PR #94 added Authorization headers to media player requests using
requests.HTTPBasicAuth
as a header, this class is intended to be used as a parameter to requests package https://requests.readthedocs.io/en/latest/user/authentication/#basic-authentication.Looking at source, you can see it will not serialize to string automagically, it uses the
__call__
method to mutate the requests object https://github.com/psf/requests/blob/main/requests/auth.py#L95You could see this happening on HA:
I changed this to use
aiohttp.BasicAuth
and pass the authentication to the request, instead of the headers https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.BasicAuth https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.requestBefore this change, I was getting some errors as I commented here https://github.com/roleoroleo/yi-hack_ha_integration/pull/94#issuecomment-1257166096