{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/lexers/__init__.py#L229-L265","documentation":"Raised by get_lexer_for_mimetype when no lexer's mimetype list (builtin or plugin) contains the supplied mimetype string.","triggerScenarios":"get_lexer_for_mimetype('application/x-foo') where no lexer advertises that mimetype, or a typo'd mimetype.","commonSituations":"Web app dispatching highlight off a Content-Type header for an unsupported type; non-standard mimetype; plugin providing the mimetype not installed.","solutions":["Map the mimetype to a known lexer alias yourself and use get_lexer_by_name.","Register a plugin lexer that advertises the mimetype.","Verify the mimetype against get_all_lexers() mimetypes."],"exampleFix":"# before\nlex = get_lexer_for_mimetype('application/x-foo')\n# after\nlex = get_lexer_by_name('python')  # explicit mapping","handlingStrategy":"fallback","validationCode":"MIME_FALLBACK = {'application/x-foo': 'python'}\nfrom pygments.lexers import get_lexer_for_mimetype, get_lexer_by_name\nfrom pygments.util import ClassNotFound\ndef lexer_for_mime(mime):\n    try:\n        return get_lexer_for_mimetype(mime)\n    except ClassNotFound:\n        return get_lexer_by_name(MIME_FALLBACK.get(mime, 'text'))","typeGuard":null,"tryCatchPattern":"from pygments.util import ClassNotFound\nfrom pygments.lexers import TextLexer\ntry:\n    lex = get_lexer_for_mimetype(mime)\nexcept ClassNotFound:\n    lex = TextLexer()","preventionTips":["Keep a mimetype-to-alias fallback map.","Don't assume arbitrary mimetypes are registered."],"tags":["pygments","lexer","mimetype","lookup"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}