home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.7k stars 28.86k forks source link

If swiss_public_transport gets an error, stacktrace in log #119137

Open cniekel opened 3 weeks ago

cniekel commented 3 weeks ago

The problem

Apparently, I'm over my daily quota with swiss_public_transport plugin.

The UI shows "Failed setup, will retry: Timeout while connecting for entry A B"

(I have 3 connections setup, this is printed for each of them)

I think it would be nicer if the UI would show the "Too Many Requests" message.

The log ends up with entries like:

2024-06-08 15:30:28.478 ERROR (MainThread) [opendata_transport] Response from transport.opendata.ch: 429, message='Too Many Requests', url=URL('http://transport.opendata.ch/v1/connections?from=X&to=Y&limit=3&page=0&isArrivalTime=0&direct=0&sleeper=0&couchette=0&bike=0')
2024-06-08 15:30:42.699 ERROR (MainThread) [opendata_transport] Response from transport.opendata.ch: 429, message='Too Many Requests', url=URL('http://transport.opendata.ch/v1/connections?from=8503063&to=8503065&limit=3&page=0&isArrivalTime=0&direct=0&sleeper=0&couchette=0&bike=0')
2024-06-08 15:30:45.811 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ state_attr('sensor.train_to_x', 'destination') }}    ({{ state_attr('sensor.train_to_x', 'duration').split(':')[1].lstrip("0") }}m)    : {{ states('sensor.train_to_x')[11:16] }}    - {{ state_attr('sensor.train_to_x', 'next_departure')[11:16]}} - {{ state_attr('sensor.train_to_x', 'next_on_departure')[11:16]}}
{{ state_attr('sensor.train_to_y', 'destination') }}     ({{ state_attr('sensor.train_to_y', 'duration').split(':')[1].lstrip("0") }}m)     : {{ states('sensor.train_to_y')[11:16] }}     - {{ state_attr('sensor.train_to_y', 'next_departure')[11:16]}} - {{ state_attr('sensor.train_to_y', 'next_on_departure')[11:16]}}
{{ state_attr('sensor.train_to_z', 'destination') }} ({{ state_attr('sensor.train_to_z', 'duration').split(':')[1].lstrip("0") }}m) : {{ states('sensor.train_to_z')[11:16] }} - {{ state_attr('sensor.train_to_z', 'next_departure')[11:16]}} - {{ state_attr('sensor.train_to_z', 'next_on_departure')[11:16]}}) renders=6>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 603, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2616, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 392, in call
    if not __self.is_safe_callable(__obj):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 3028, in is_safe_callable
    ) or super().is_safe_callable(obj)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 276, in is_safe_callable
    getattr(obj, "unsafe_callable", False) or getattr(obj, "alters_data", False)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'None' has no attribute 'split'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 715, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 605, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'split'

What version of Home Assistant Core has the issue?

core-2024.6.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

swiss public transport

Link to integration documentation on our website

https://www.home-assistant.io/integrations/swiss_public_transport/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-06-08 15:30:28.478 ERROR (MainThread) [opendata_transport] Response from transport.opendata.ch: 429, message='Too Many Requests', url=URL('http://transport.opendata.ch/v1/connections?from=X&to=Y&limit=3&page=0&isArrivalTime=0&direct=0&sleeper=0&couchette=0&bike=0')
2024-06-08 15:30:42.699 ERROR (MainThread) [opendata_transport] Response from transport.opendata.ch: 429, message='Too Many Requests', url=URL('http://transport.opendata.ch/v1/connections?from=8503063&to=8503065&limit=3&page=0&isArrivalTime=0&direct=0&sleeper=0&couchette=0&bike=0')
2024-06-08 15:30:45.811 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ state_attr('sensor.train_to_x', 'destination') }}    ({{ state_attr('sensor.train_to_x', 'duration').split(':')[1].lstrip("0") }}m)    : {{ states('sensor.train_to_x')[11:16] }}    - {{ state_attr('sensor.train_to_x', 'next_departure')[11:16]}} - {{ state_attr('sensor.train_to_x', 'next_on_departure')[11:16]}}
{{ state_attr('sensor.train_to_y', 'destination') }}     ({{ state_attr('sensor.train_to_y', 'duration').split(':')[1].lstrip("0") }}m)     : {{ states('sensor.train_to_y')[11:16] }}     - {{ state_attr('sensor.train_to_y', 'next_departure')[11:16]}} - {{ state_attr('sensor.train_to_y', 'next_on_departure')[11:16]}}
{{ state_attr('sensor.train_to_z', 'destination') }} ({{ state_attr('sensor.train_to_z', 'duration').split(':')[1].lstrip("0") }}m) : {{ states('sensor.train_to_z')[11:16] }} - {{ state_attr('sensor.train_to_z', 'next_departure')[11:16]}} - {{ state_attr('sensor.train_to_z', 'next_on_departure')[11:16]}}) renders=6>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 603, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2616, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 392, in call
    if not __self.is_safe_callable(__obj):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 3028, in is_safe_callable
    ) or super().is_safe_callable(obj)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 276, in is_safe_callable
    getattr(obj, "unsafe_callable", False) or getattr(obj, "alters_data", False)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'None' has no attribute 'split'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 715, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 605, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'split'

Additional information

No response

home-assistant[bot] commented 3 weeks ago

Hey there @fabaff, @miaucl, mind taking a look at this issue as it has been labeled with an integration (swiss_public_transport) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `swiss_public_transport` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign swiss_public_transport` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


swiss_public_transport documentation swiss_public_transport source (message by IssueLinks)

miaucl commented 3 weeks ago

You mean you reached your quota and then you restarted the. Integration? Because when you reach it while the integration is running, it should not be this messy.

I agree that it should also not be this messy in you usecase :)

Will have a look at it if I can reproduce that.

cniekel commented 3 weeks ago

I did the update to 2024.6 today, so there was definitely some restarting. No idea if I hit the quota limit before the update already.

On Sat, Jun 8, 2024 at 3:59 PM Cyrill Raccaud @.***> wrote:

You mean you reached your quota and then you restarted the. Integration? Because when you reach it while the integration is running, it should not be this messy.

I agree that it should also not be this messy in you usecase :)

Will have a look at it if I can reproduce that.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/119137#issuecomment-2156047014, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAJXRZE3LFK6CNESRHN5JDZGME3BAVCNFSM6AAAAABJAAE2DSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGA2DOMBRGQ . You are receiving this because you authored the thread.Message ID: @.***>

cniekel commented 3 weeks ago

Sorry, please disregard

Op za 8 jun 2024 19:56 schreef Chris Niekel @.***>:

Du wurdest eingeladen zum Rätsel lösen mit Freunden. Klicke den folgenden Link um dem Spiel beizutreten. Der Link ist für eine Stunde gültig:

https://www.coopzeitung.ch/de/raetsel/kreuzwortraetsel.html#gameId=2715672d-e523-4940-8adc-e1ee2bb6d461

Anleitung zum Rätsel: Verwende die Tastatur deines Gerätes um Wörter oder einzelne Buchstaben in das Rätselgitter einzutragen. Klicke dazu in das gewünschte Antwort-Feld. Durch erneutes Klicken in das Feld kann die Schreibrichtung (horizontal / vertikal) geändert werden. Umlaute müssen ausgeschrieben werden.

Op za 8 jun 2024 16:25 schreef Chris Niekel @.***>:

I did the update to 2024.6 today, so there was definitely some restarting. No idea if I hit the quota limit before the update already.

On Sat, Jun 8, 2024 at 3:59 PM Cyrill Raccaud @.***> wrote:

You mean you reached your quota and then you restarted the. Integration? Because when you reach it while the integration is running, it should not be this messy.

I agree that it should also not be this messy in you usecase :)

Will have a look at it if I can reproduce that.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/119137#issuecomment-2156047014, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAJXRZE3LFK6CNESRHN5JDZGME3BAVCNFSM6AAAAABJAAE2DSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGA2DOMBRGQ . You are receiving this because you authored the thread.Message ID: @.***>

fabaff commented 3 weeks ago

The number of requests per day is limited to 1000 route queries and 10080 departure/arrival tables

First time I hear that a person reached the limit.

The traceback seems to come from the template handling as there is no data to process.

miaucl commented 3 weeks ago

I reach it quite easily. If you do a request each minute you reach it. 60*24=1440 requests per day.