{"record":{"id":"82d552de11478baa","repo":"pypa/pip","slug":"no-lexer-for-mimetype-mime-r-found","errorCode":null,"errorMessage":"no lexer for mimetype {_mime!r} found","messagePattern":"no lexer for mimetype (.+?) found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/lexers/__init__.py","lineNumber":247,"sourceCode":"\n\ndef get_lexer_for_mimetype(_mime, **options):\n    \"\"\"\n    Return a `Lexer` subclass instance that has `mime` in its mimetype\n    list. The lexer is given the `options` at its instantiation.\n\n    Will raise :exc:`pygments.util.ClassNotFound` if not lexer for that mimetype\n    is found.\n    \"\"\"\n    for modname, name, _, _, mimetypes in LEXERS.values():\n        if _mime in mimetypes:\n            if name not in _lexer_cache:\n                _load_lexers(modname)\n            return _lexer_cache[name](**options)\n    for cls in find_plugin_lexers():\n        if _mime in cls.mimetypes:\n            return cls(**options)\n    raise ClassNotFound(f'no lexer for mimetype {_mime!r} found')\n\n\ndef _iter_lexerclasses(plugins=True):\n    \"\"\"Return an iterator over all lexer classes.\"\"\"\n    for key in sorted(LEXERS):\n        module_name, name = LEXERS[key][:2]\n        if name not in _lexer_cache:\n            _load_lexers(module_name)\n        yield _lexer_cache[name]\n    if plugins:\n        yield from find_plugin_lexers()\n\n\ndef guess_lexer_for_filename(_fn, _text, **options):\n    \"\"\"\n    As :func:`guess_lexer()`, but only lexers which have a pattern in `filenames`\n    or `alias_filenames` that matches `filename` are taken into consideration.\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pygments/lexers/__init__.py#L229-L265","documentation":"Raised by get_lexer_for_mimetype() as a ClassNotFound when neither any builtin lexer (iterated via LEXERS.values() mimetypes, lines 239-243) nor any plugin lexer (lines 244-246) has _mime in its mimetypes list. The mimetype simply is not registered with any known lexer.","triggerScenarios":"Calling get_lexer_for_mimetype('application/x-my-format') where that mimetype is declared by no lexer; passing a mimetype with incorrect casing or a trailing parameter that does not exactly match a registered entry.","commonSituations":"Web apps reading Content-Type headers and passing the raw value (including charset params like 'text/plain; charset=utf-8') directly; typos in the mimetype string; a mimetype that exists in a newer Pygments version than the vendored one bundled in pip.","solutions":["Strip Content-Type parameters before calling: _mime = header.split(';')[0].strip().","Cross-check the mimetype against get_all_lexers() to see which mimetypes are actually registered.","Fall back to get_lexer_by_name() with a sensible default alias if the mimetype lookup fails."],"exampleFix":"// before\nlexer = get_lexer_for_mimetype(content_type)  # 'text/x-python; charset=utf-8'\n\n// after\nmime = content_type.split(';')[0].strip()\nlexer = get_lexer_for_mimetype(mime)","handlingStrategy":"validation","validationCode":"from pygments.lexers import get_all_lexers\ndef known_mimetypes():\n    return {m for *_, mimes in get_all_lexers() for m in mimes}\ndef is_known_mime(mime):\n    return mime in known_mimetypes()","typeGuard":null,"tryCatchPattern":"from pygments.lexers import get_lexer_for_mimetype, get_lexer_by_name\nfrom pygments.util import ClassNotFound\ntry:\n    lexer = get_lexer_for_mimetype(mime)\nexcept ClassNotFound:\n    lexer = get_lexer_by_name('text')","preventionTips":["Strip Content-Type parameters (split on ';') before passing the mimetype.","Cache the set of registered mimetypes from get_all_lexers() to validate quickly."],"tags":["pygments","lexer","mimetype","class-not-found"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}