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

Receiving http status 429 (Too many requests) only throws exception #331

Open
Giermann opened this issue Jan 15, 2025 · 7 comments
Open

Comments

@Giermann
Copy link
Contributor

Giermann commented Jan 15, 2025

This error is often returned by the API when too many requests have been sent.
It should be handled, ideally in advance by checking for a header "X-RateLimit-Remaining", which is included in responses whenever there are less than 15 remaining calls allowed, see https://community.home-assistant.io/t/skoda-connect/88288/76

Actual output:

Invalid status for GET request to /v2/vehicle-status/TMB....../driving-range: 429
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/myskoda/rest_api.py", line 99, in _make_request
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/aiohttp/client_reqrep.py", line 1161, in raise_for_status
    raise ClientResponseError(
    ...<5 lines>...
    )
aiohttp.client_exceptions.ClientResponseError: 429, message='Too Many Requests', url='https://mysmob.api.connect.skoda-auto.cz/api/v2/vehicle-status/TMB....../driving-range'
@prvakt
Copy link
Collaborator

prvakt commented Jan 15, 2025

New MySkoda API unfortunately doesn't provide any way to check how much request we have remaining

@prvakt prvakt added the wontfix This will not be worked on label Jan 15, 2025
@Giermann
Copy link
Contributor Author

Unfortunately it does not have a "non-destructive" way to find out - but are you sure, that it does not contain the extra header in the last 15 responses?

But even if not, the response status 429 should be caught to output a "known" error message instead of the generic traceback.
This is helpful for unexpected responses, but 429 should be expected in some way.
If you agree to remove the "wontfix" for that part, I could start to create a pull request...

@prvakt prvakt removed the wontfix This will not be worked on label Jan 16, 2025
@WebSpider
Copy link
Contributor

It is entirely possible MySkoda has added this in the last year. A year ago when i did some http debugging, api credit headers were missing.

@WebSpider
Copy link
Contributor

I just checked: The API credits are not part of the response when requesting driving range to this date:

Trace: GET https://mysmob.api.connect.skoda-auto.cz/api/v2/vehicle-stat - response: 200 (186 bytes) ((b'content-type', b'application/json'), (b'content-length', b'186'), (b'cache-control', b'no-cache, no-store, max-age=0, must-revalidate'), (b'pragma', b'no-cache'), (b'expires', b'0'), (b'x-content-type-options', b'nosniff'), (b'strict-transport-security', b'max-age=31536000 ; includeSubDomains'), (b'x-frame-options', b'DENY'), (b'x-xss-protection', b'0'), (b'referrer-policy', b'no-referrer'), (b'date', b'Thu, 16 Jan 2025 08:57:49 GMT')) {"carType":"electric","totalRangeInKm":255,"primaryEngineRange":{"engineType":"electric","currentSoCInPercent":70,"remainingRangeInKm":255},"carCapturedTimestamp":"2025-01-16T07:38:37Z"}

@Giermann
Copy link
Contributor Author

I added the output of traces to my "daemon" script and will keep an eye of it.
Can you tell me, how to get the extra headers "((b'content-type', b'application/json'), ...)" to traces?

@WebSpider
Copy link
Contributor

Can you tell me, how to get the extra headers "((b'content-type', b'application/json'), ...)" to traces?

I made a dirty hack that also logged response.raw_headers in the logging line

@Giermann
Copy link
Contributor Author

Okay, thanks.
I followed your example to log a warning whenever the 'x-ratelimit-remaining' header is present in any response while tracing is enabled and will watch the results...

If I find it at any time, I'll report back because I have no clue where I could add this check without tracing and how to handle it in general. Add some tag to every event/response? We will discuss this later.

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

No branches or pull requests

3 participants