{"record":{"id":"5ed465ee6275527c","repo":"aio-libs/aiohttp","slug":"only-one-of-data-or-body-should-be-specified","errorCode":null,"errorMessage":"only one of data or body should be specified","messagePattern":"only one of data or body should be specified","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aiohttp/web_response.py","lineNumber":782,"sourceCode":"\ndef json_bytes_response(\n    data: Any = sentinel,\n    *,\n    dumps: JSONBytesEncoder,\n    body: bytes | None = None,\n    status: int = 200,\n    reason: str | None = None,\n    headers: LooseHeaders | None = None,\n    content_type: str = \"application/json\",\n) -> Response:\n    \"\"\"Create a JSON response using a bytes-returning encoder.\n\n    Use this when your JSON encoder (like orjson) returns bytes\n    instead of str, avoiding the encode/decode overhead.\n    \"\"\"\n    if data is not sentinel:\n        if body is not None:\n            raise ValueError(\"only one of data or body should be specified\")\n        else:\n            body = dumps(data)\n    return Response(\n        body=body,\n        status=status,\n        reason=reason,\n        headers=headers,\n        content_type=content_type,\n    )\n","sourceCodeStart":764,"sourceCodeEnd":792,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/web_response.py#L764-L792","documentation":"Raised by the bytes-encoding JSON response helper (`json_response_with_bytes` / the bytes-returning-encoder variant) when both `data=` and `body=` are passed. The helper expects either a value to encode via the bytes-returning `dumps` (data) or pre-encoded bytes (body), not both.","triggerScenarios":"Calling the bytes JSON helper with `data=obj, body=orjson.dumps(obj)`. Common when migrating from `json_response` to the bytes variant and forgetting to drop one argument.","commonSituations":"Using orjson/mujson (which return bytes) and double-encoding by passing both the object and its serialized form; helper refactor that forwards both kwargs.","solutions":["Pass exactly one: `data=obj` to have the helper encode it via `dumps`, or `body=encoded_bytes` to use pre-encoded bytes.","Prefer `data=obj` and let the helper call `dumps` once.","If you already have bytes, drop the `data=` argument.","Keep wrapper signatures explicit about which channel to use."],"exampleFix":"// before\nreturn json_response_with_bytes(data=obj, body=orjson.dumps(obj))\n\n// after\nreturn json_response_with_bytes(data=obj)  # helper invokes orjson.dumps","handlingStrategy":"validation","validationCode":"def safe_json_bytes(data=sentinel, body=None, **kw):\n    if data is not sentinel:\n        assert body is None, 'pass only one of data or body'\n    return json_response_with_bytes(data=data, body=body, **kw)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass exactly one of data= or body= to the bytes JSON helper.","Prefer data= and let the helper encode via dumps.","Drop data= when you already have encoded bytes.","Keep helper signatures explicit about the chosen channel."],"tags":["aiohttp","web-response","json-response","orjson","validation"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}