{"id":"3b570cf569129174","repo":"pydantic/pydantic","slug":"unknown-content-type-content-type-3b570c","errorCode":null,"errorMessage":"Unknown content-type: {content_type}","messagePattern":"Unknown content-type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pydantic/v1/parse.py","lineNumber":30,"sourceCode":"    pickle = 'pickle'\n\n\ndef load_str_bytes(\n    b: StrBytes,\n    *,\n    content_type: str = None,\n    encoding: str = 'utf8',\n    proto: Protocol = None,\n    allow_pickle: bool = False,\n    json_loads: Callable[[str], Any] = json.loads,\n) -> Any:\n    if proto is None and content_type:\n        if content_type.endswith(('json', 'javascript')):\n            pass\n        elif allow_pickle and content_type.endswith('pickle'):\n            proto = Protocol.pickle\n        else:\n            raise TypeError(f'Unknown content-type: {content_type}')\n\n    proto = proto or Protocol.json\n\n    if proto == Protocol.json:\n        if isinstance(b, bytes):\n            b = b.decode(encoding)\n        return json_loads(b)\n    elif proto == Protocol.pickle:\n        if not allow_pickle:\n            raise RuntimeError('Trying to decode with pickle with allow_pickle=False')\n        bb = b if isinstance(b, bytes) else b.encode()\n        return pickle.loads(bb)\n    else:\n        raise TypeError(f'Unknown protocol: {proto}')\n\n\ndef load_file(\n    path: Union[str, Path],","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/pydantic/pydantic/blob/2e5f0e2b4218de31709f1cf9c5bc61ea97a68835/pydantic/v1/parse.py#L12-L48","documentation":"Raised as `TypeError` by `load_str_bytes` when a `content_type` is supplied but does not end with `json`/`javascript` and (with `allow_pickle`) not `pickle`. It is pydantic v1's way of saying it cannot infer the serialization protocol from the given MIME/content-type.","triggerScenarios":"Calling `parse_obj_as` / `load_str_bytes` / `load_file` with `content_type` set to something pydantic does not recognize (e.g. `content_type='application/xml'`, `content_type='msgpack'`, or a typo like `content_type='jso'`).","commonSituations":"Feeding data tagged with a custom or upstream content-type, mis-typing the content-type string, or assuming pydantic supports arbitrary MIME types for deserialization.","solutions":["Pass the protocol explicitly via `proto=Protocol.json` instead of relying on content_type.","If you genuinely have a non-JSON payload, pre-decode it yourself and pass the Python object.","Correct or drop the content_type argument so it is one of json/javascript (or pickle with allow_pickle=True)."],"exampleFix":"// before\nfrom pydantic.v1.parse import load_str_bytes\nload_str_bytes(b'...', content_type='application/xml')\n\n// after\nfrom pydantic.v1.parse import load_str_bytes, Protocol\nload_str_bytes(b'...', proto=Protocol.json)","handlingStrategy":"validation","validationCode":"from pydantic.v1.parse import Protocol\n_KNOWN = ('json', 'javascript', 'pickle')\ndef content_type_ok(ct: str, allow_pickle: bool) -> bool:\n    return ct.endswith(('json', 'javascript')) or (allow_pickle and ct.endswith('pickle'))\n# assert content_type_ok(content_type, allow_pickle) before calling","typeGuard":null,"tryCatchPattern":"except TypeError:\n    # unsupported content_type; fall back to explicit proto=Protocol.json","preventionTips":["Prefer passing proto= explicitly rather than content_type.","Validate the content_type against the known suffixes before deserializing."],"tags":["parsing","serialization","content-type"],"analyzedSha":"2e5f0e2b4218de31709f1cf9c5bc61ea97a68835","analyzedAt":"2026-08-04T19:54:21.281Z","schemaVersion":2}