{"record":{"id":"64db8054b3f49d75","repo":"tursodatabase/turso","slug":"invalid-value-in-server-response-e","errorCode":null,"errorMessage":"invalid value in server response: {e}","messagePattern":"invalid value in server response: (.+?)","errorType":"exception","errorClass":"ProtocolError","httpStatus":null,"severity":"error","filePath":"serverless/python/turso_serverless/protocol.py","lineNumber":75,"sourceCode":"        if typ == \"null\":\n            return None\n        if typ == \"integer\":\n            return int(pv[\"value\"])\n        if typ == \"float\":\n            raw = pv[\"value\"]\n            # A null value encodes a non-finite float (section 8.2); the\n            # spec says to decode it as NaN.\n            if raw is None:\n                return math.nan\n            return float(raw)\n        if typ == \"text\":\n            return pv[\"value\"]\n        if typ == \"blob\":\n            # The server may omit base64 padding (section 8).\n            b64 = pv[\"base64\"]\n            return base64.b64decode(b64 + \"=\" * (-len(b64) % 4))\n    except (KeyError, TypeError, ValueError) as e:\n        raise ProtocolError(f\"invalid value in server response: {e}\") from None\n    raise ProtocolError(f\"unsupported value type in server response: {typ!r}\")\n\n\ndef build_batch_step(\n    sql: str,\n    args: Optional[list] = None,\n    named_args: Optional[list[tuple[str, Any]]] = None,\n    want_rows: bool = True,\n    condition: Optional[dict] = None,\n) -> dict:\n    \"\"\"Build a batch step for a cursor request (section 7).\"\"\"\n    encoded_args = [encode_value(a) for a in args] if args else []\n    encoded_named = (\n        [{\"name\": name, \"value\": encode_value(val)} for name, val in named_args]\n        if named_args\n        else []\n    )\n    step: dict = {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/serverless/python/turso_serverless/protocol.py#L57-L93","documentation":"ProtocolError raised by decode_value() (protocol.py:53-75) when a value object inside a server response is malformed: a missing 'type' key (KeyError), a non-dict value (TypeError), or an unparseable integer/float/base64 payload (ValueError). It means the response violated protocol section 8; the original exception detail is embedded in the message. Callers inside execute_stmt treat any ProtocolError as fatal for the stream and reset the baton.","triggerScenarios":"A server or intermediary returns truncated or rewritten JSON in the row payload of a /v3/cursor response; a server version emits value shapes the client does not understand; a middlebox corrupts field names.","commonSituations":"Version skew between the turso_serverless client and the server; self-hosted or custom proxies on the path; response-mutating service meshes or CDNs; extremely rare memory/network corruption that still yields valid UTF-8.","solutions":["Confirm the URL points at the Turso SQL-over-HTTP endpoint the client supports and that client/server versions match","Upgrade the turso_serverless package (and the server) to aligned releases","Remove or bypass intermediaries that rewrite response bodies, then retry on the fresh stream the driver already started","If it persists, capture the failing response (HTTP logging proxy) and report it as a protocol violation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from turso_serverless.protocol import ProtocolError\n\ntry:\n    rows = conn.execute(sql).fetchall()\nexcept ProtocolError as e:\n    if not str(e).startswith(\"invalid value in server response\"):\n        raise\n    # stream already reset; a fresh connection rules out client-side state\n    conn = connect(URL, auth_token=TOKEN)\n    rows = conn.execute(sql).fetchall()  # retry once, then surface","preventionTips":["Pin client and server to compatible protocol versions in your lockfile/deploy","Terminate TLS directly to the database; avoid middleboxes that rewrite response bodies","Log the raw response when this fires — it is evidence of a spec violation worth reporting"],"tags":["python","protocol","response-parsing","server"],"backgroundTag":"malformed-server-response","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}