commaai/openpilot · error · ValueError
Invalid activation code format
Error message
Invalid activation code format
What it means
parse_lpa_activation_code() raises ValueError when the string does not start with 'LPA:'. The expected format is 'LPA:1$smdp.example.com$MATCHING-ID' (GSMA activation code).
Source
Thrown at openpilot/common/esim/lpa.py:614
def parse_metadata(b64_metadata: str) -> dict:
root = find_tag(b64d(b64_metadata), TAG_PROFILE_METADATA)
if root is None:
raise RuntimeError("Invalid profileMetadata")
return decode_struct(root, PROFILE)
def cancel_session(client: AtClient, transaction_id: bytes, reason: int = 127) -> str:
content = encode_tlv(0x80, transaction_id) + encode_tlv(0x81, bytes([reason]))
response = es10x_command(client, encode_tlv(TAG_CANCEL_SESSION, content))
return b64e(response)
def parse_lpa_activation_code(activation_code: str) -> tuple[str, str]:
"""Parse 'LPA:1$smdp.example.com$MATCHING-ID' into (smdp_address, matching_id)."""
if not activation_code.startswith("LPA:"):
raise ValueError("Invalid activation code format")
parts = activation_code[4:].split("$")
if len(parts) != 3:
raise ValueError("Invalid activation code format")
return parts[1], parts[2]
def _b64_field(data: dict, key: str) -> str:
return base64_trim(data[key])
def _cancel_session_safe(client: AtClient, smdp: str, tx_id: str, session: requests.Session) -> None:
b64_cancel = ""
try:
b64_cancel = cancel_session(client, b64d(tx_id))
except Exception:
pass
try:
es9p_request(smdp, "cancelSession", {"transactionId": tx_id, "cancelSessionResponse": b64_cancel}, "CancelSession", session=session)View on GitHub (pinned to 516ec1e682)
Solutions
- Use a standard GSMA activation code starting with 'LPA:1$'
- Strip whitespace/newlines from scanned QR content before passing it in
- If only a host is available, construct the code as f"LPA:1${host}$"
Example fix
// before download_profile(client, "smdp.example.com") // after download_profile(client, "LPA:1$smdp.example.com$")
Defensive patterns
Strategy: validation
Validate before calling
def is_activation_code(s: str) -> bool:
s = s.strip()
return s.startswith("LPA:") and len(s[4:].split("$")) == 3 Try / catch
try:
smdp, mid = parse_lpa_activation_code(code)
except ValueError:
# prompt user to rescan QR
... Prevention
- Strip whitespace from scanned QR content
- Validate the LPA: prefix before starting the download flow
When it happens
Trigger: Passing an activation code like '1$smdp$mid' or a raw SM-DP+ URL without the LPA: prefix to download_profile/parse_lpa_activation_code.
Common situations: User scans a non-standard QR code; the code was copy-pasted with the prefix stripped or whitespace-prefixed; a QR containing a raw URL is used instead of an activation code.
Related errors
- Profile nickname must be 64 bytes or less
- Confirmation code required but not provided
- Profile installation failed at {cmd_name}: {err_name}
- Invalid profileMetadata
- System time is not set; TLS certificate validation requires
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/7eebc6e72d20cca4.
Report an issue: GitHub.