No data - "Cannot retrieve data for direction..."
The problem
Probably for a long time my sensors can't get data anymore. Sensor states are unknown.
What version of Home Assistant Core has the issue?
core-2023.3.6
What version of DeutscheBahn Integration has the issue?
2.0.4
What type of installation are you running?
Home Assistant OS
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht
Logger: custom_components.deutschebahn.sensor
Source: custom_components/deutschebahn/sensor.py:154
Integration: Deutsche Bahn (documentation, issues)
First occurred: 09:23:50 (1 occurrences)
Last logged: 09:23:50
Cannot retrieve data for direction: 'StartLocation' 'TargetLocation'
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 244, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/local/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f4984b8b0>: Failed to establish a new connection: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='mobile.bahn.de', port=80): Max retries exceeded with url: /bin/mobil/query.exe/dox?S=StartLocation&Z=TargetLocation&date=30.08.23&time=09%3A23&start=1&REQ0JourneyProduct_opt0=1 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4984b8b0>: Failed to establish a new connection: [Errno -3] Try again'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/deutschebahn/sensor.py", line 117, in async_update
self.connections = await hass.async_add_executor_job(
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/deutschebahn/sensor.py", line 154, in fetch_schiene_connections
data = self.schiene.connections(
File "/usr/local/lib/python3.10/site-packages/schiene/schiene.py", line 149, in connections
rsp = requests.get('http://mobile.bahn.de/bin/mobil/query.exe/dox?', params=query)
File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='mobile.bahn.de', port=80): Max retries exceeded with url: /bin/mobil/query.exe/dox?S=StartLocation&Z=TargetLocation&date=30.08.23&time=09%3A23&start=1&REQ0JourneyProduct_opt0=1 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4984b8b0>: Failed to establish a new connection: [Errno -3] Try again'))
Additional information
Please note I replaced the actually used Start & Target Location in the log output above by "StartLocation" and "TargetLocation".
Additionally found in HA log:
2023-08-29 00:19:20.872 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
tasks = [
TypeError: 'DeutscheBahnSensor' object is not iterable
Unfortunatly I am unable to reproduce it with the trains I am using. Could you please try removing the trains and then set them up again from the deutschebahn HA ui?
Could you please try removing the trains and then set them up again from the deutschebahn HA ui?
That's what I did first (same start / stop combination) before creating this issue.
Interestingly, it magically healed itself around 3rd of september (02:36 in the night) without any action or correlation (no HA Core restart, no integration reload etc.):
Especially because of this I was hoping the log output itself would at least allow to say "it's a local issue in the integration" or "it's an API issue, Deutsche Bahn simply did not provide the requested data". Otherwise, this might happen at any time again...