kvj / hass_nuki_ng

Better support for Nuki devices in the Home Assistant
MIT License
185 stars 36 forks source link

Failed to get latest data: ("Connection broken: InvalidChunkLength(got length b'HTTP/1.1 200 OK\\r\\n', 0 bytes read)", InvalidChunkLength(got length b'HTTP/1.1 200 OK\r\n', 0 bytes read) #60

Open KitHubek opened 2 years ago

KitHubek commented 2 years ago

Logger: custom_components.nuki_ng.nuki Source: custom_components/nuki_ng/nuki.py:72 Integration: Nuki Lock (documentation, issues) First occurred: 12:44:29 (2 occurrences) Last logged: 12:45:00

Failed to get latest data: ("Connection broken: InvalidChunkLength(got length b'HTTP/1.1 200 OK\r\n', 0 bytes read)", InvalidChunkLength(got length b'HTTP/1.1 200 OK\r\n', 0 bytes read))

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 700, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b'HTTP/1.1 200 OK\r\n'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 441, in _error_catcher
    yield
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 767, in read_chunked
    self._update_chunk_length()
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 704, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'HTTP/1.1 200 OK\r\n', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 760, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 575, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 796, in read_chunked
    self._original_response.close()
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/urllib3/response.py", line 458, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'HTTP/1.1 200 OK\\r\\n', 0 bytes read)", InvalidChunkLength(got length b'HTTP/1.1 200 OK\r\n', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nuki_ng/nuki.py", line 344, in _update
    bridge_info = await self.api.bridge_info()
  File "/config/custom_components/nuki_ng/nuki.py", line 72, in bridge_info
    return await self.async_json(lambda r: r.get(self.bridge_url("/info")))
  File "/config/custom_components/nuki_ng/nuki.py", line 36, in async_json
    response = await self.hass.async_add_executor_job(lambda: cb(requests))
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/nuki_ng/nuki.py", line 36, in <lambda>
    response = await self.hass.async_add_executor_job(lambda: cb(requests))
  File "/config/custom_components/nuki_ng/nuki.py", line 72, in <lambda>
    return await self.async_json(lambda r: r.get(self.bridge_url("/info")))
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 687, in send
    r.content
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 838, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 763, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'HTTP/1.1 200 OK\\r\\n', 0 bytes read)", InvalidChunkLength(got length b'HTTP/1.1 200 OK\r\n', 0 bytes read))
labactani commented 2 years ago

I have the exact same problem...and then all the entities become unavailable. But if I reload the integration, it starts working fine again....

KitHubek commented 2 years ago

update with entities behaviour. the same here as post before. After that error i provided at my first post, all entities are unavialable :/

enkama commented 2 years ago

Same exact stuff for me.

kvj commented 2 years ago

Is it a persistent problem? Connection issues happen from time to time, but all entities should be back online after the next successful polling (30 seconds by default)

enkama commented 2 years ago

I mean the connection issues happen pretty often ngl. The question is if its coming from nuki_ng or from nuki itself.

Also this comes up in the console.

2022-08-02 17:13:00.765 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140293901890416] Http response: 503
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/config/custom_components/nuki_ng/lock.py", line 53, in async_lock
    await self.coordinator.action(self.device_id, "lock")
  File "/config/custom_components/nuki_ng/nuki.py", line 392, in action
    result = await self.api.bridge_lock_action(dev_id, action, device_type)
  File "/config/custom_components/nuki_ng/nuki.py", line 93, in bridge_lock_action
    return await self.async_json(
  File "/config/custom_components/nuki_ng/nuki.py", line 38, in async_json
    raise ConnectionError(f"Http response: {response.status_code}")
ConnectionError: Http response: 503
alexdelprete commented 2 years ago

The bridge unfortunately supports only one http request at a time. If multiple http requests are received, the other not processed receive the 503 response. This means that some other component is querying the bridge.

Make sure you uninstalled the official HA Nuki integration, or make sure you're not using the Nuki mobile app that could potentially query the bridge, but if it happens very often, it shouldn't be the mobile app, that you occasionally open.