Repository navigation
vehicle SAIC iSMART: HTTP-401/403 Relogin - #4249
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active issue remains because the shared response hook raises HTTP errors before the intended 401/403 handling, preventing the relogin path from running.
1 open issue
What changed in this PR
This pull request extends the SAIC iSMART client’s authentication handling to recognize HTTP-level 401 and 403 responses and trigger the existing relogin flow.
Changes:
- Maps HTTP
401/403responses toSaicAuthenticationError. - Adds regression coverage for HTTP
401handling. - The production response hook currently raises before this status handling executes, and the test does not exercise that hook.
This pull request requires changes.
| File | Summary |
|---|---|
packages/modules/vehicles/saic_ismart/api.py |
Adds HTTP-level authentication error detection, but the shared response hook prevents the new handling from running in production. |
packages/modules/vehicles/saic_ismart/api_test.py |
Adds HTTP 401 regression coverage, but the mocked session bypasses the response hook and does not expose the production failure. |
Review effort: Lite
| if response.status_code in (401, 403): | ||
| # Die Cloud kann eine ungültige Session auch schon auf HTTP-Ebene ablehnen (zB nach Login in | ||
| # der iSMART-App auf dem Handy), nicht nur über das eigene code-Feld in einer 200-Antwort - | ||
| # muss hier genauso wie code=401/403 (_check_code) eine SaicAuthenticationError auslösen, | ||
| # sonst greift der automatische Relogin in _call_with_relogin() nicht. | ||
| raise SaicAuthenticationError(f"{path_with_query}: Session abgelaufen (HTTP {response.status_code})") |
There was a problem hiding this comment.
Schau bitte, ob Du statt dem if die Exception requests.HTTPError fangen kannst.
| data=encrypted_body if encrypted_body else None, headers=headers, timeout=15) | ||
| response.raise_for_status() | ||
| try: | ||
| response.raise_for_status() |
There was a problem hiding this comment.
raise_for_status wird schon als Session-Hook aufgerufen und wirft die Exception damit schon aus session.request vor dem try-except-Block. Z.99 bis 109 müssen so aussehen (geht leider nicht als Suggestion):
try:
response = session.request(
method, f"{BASE_URL}{path_with_query}",
data=encrypted_body if encrypted_body else None, headers=headers, timeout=15)
except HTTPError as exc:
if exc.response is not None and exc.response.status_code in (401, 403):
# Session kann auch schon auf HTTP-Ebene abgelehnt werden, nicht nur über code= in der Antwort.
raise SaicAuthenticationError(
f"{path_with_query}: Session abgelaufen (HTTP {exc.response.status_code})") from exc
raise

Die Cloud kann eine ungültige Session auch auf HTTP-Ebene mit 401/403 ablehnen (zB nach Login in der iSMART-App auf dem Handy), nicht nur über das eigene code-Feld in einer 200-Antwort. Bisher wurde das nicht als Auth-Fehler erkannt, der automatische Relogin griff also nicht.
Summary by Sourcery
Handle HTTP-level session rejection in the SAIC iSMART API to enable automatic relogin.
Bug Fixes:
Tests: