Skip to content

vehicle SAIC iSMART: HTTP-401/403 Relogin - #4249

Merged
LKuemmel merged 3 commits into
openWB:masterfrom
seaspotter:saic-ismart-http-401-relogin
Nov 4, 2026
Merged

LKuemmel merged 3 commits into
openWB:masterfrom
seaspotter:saic-ismart-http-401-relogin

Conversation

@seaspotter

@seaspotter seaspotter commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • Recognize HTTP 401 and 403 responses from the SAIC iSMART cloud as authentication failures so automatic relogin can be triggered.

Tests:

  • Add coverage for converting an HTTP 401 error into a SAIC authentication error.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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/403 responses to SaicAuthenticationError.
  • Adds regression coverage for HTTP 401 handling.
  • 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

Comment on lines +100 to +105
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})")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schau bitte, ob Du statt dem if die Exception requests.HTTPError fangen kannst.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, erl.

data=encrypted_body if encrypted_body else None, headers=headers, timeout=15)
response.raise_for_status()
try:
response.raise_for_status()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erl

@LKuemmel
LKuemmel merged commit d967ef3 into openWB:master Nov 4, 2026
2 checks passed
@seaspotter
seaspotter deleted the saic-ismart-http-401-relogin branch November 4, 2026 11:08
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

Successfully merging this pull request may close these issues.

3 participants