Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch RateLimit/Throttle as as exception? #3

Closed
vikramgorla opened this issue Sep 10, 2018 · 2 comments · Fixed by #4 or home-assistant/core#16723
Closed

Catch RateLimit/Throttle as as exception? #3

vikramgorla opened this issue Sep 10, 2018 · 2 comments · Fixed by #4 or home-assistant/core#16723

Comments

@vikramgorla
Copy link
Contributor

Fabian,

It looks like async_get_data is proceeding to get connections info even if the response is not 200 (e.g,. ratelimiting with http 429) - do you think it helps if an error is raised when the quota is exceeded?

Sample exception raised in homeassistant when the ratelimiter of opendata.ch blocks you

Update for sensor.sbb_home_work fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 224, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 351, in async_device_update
    yield from self.async_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/swiss_public_transport.py", line 129, in async_update
    await self._opendata.async_get_data()
  File "/usr/local/lib/python3.6/site-packages/opendata_transport/__init__.py", line 47, in async_get_data
    self.from_id = data['from']['id']
KeyError: 'from'

Response from opendata.ch

Request URL: http://transport.opendata.ch/v1/connections?from=Bex&to=Vevey
Request Method: GET
Status Code: 429 Too Many Requests

{"errors":[{"message":"Rate limit error from timetable.search.ch: Too many requests, try again tomorrow."}]}

Cheers,

@fabaff
Copy link
Member

fabaff commented Sep 11, 2018

Yes, it would. I never ran into issues with the rate limit because I only needed the data for one connection.

@vikramgorla
Copy link
Contributor Author

Thank you Fabian, I will submit a pull request and see how can we reduce number of calls made to api (e.g,. call the api only just before the next known train time in a rate optimized mode controlled by a flag,...) in home assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants